From dd23cbd8a1caf00f0b842aff514d2907d545a403 Mon Sep 17 00:00:00 2001 From: Ariel Costas Guerrero <94913521+arielcostas@users.noreply.github.com> Date: Wed, 21 Aug 2024 10:10:38 +0200 Subject: Bring back the blog --- src/pages/blog.astro | 68 +++++++++++++++++++++++++++++++++++++++++++++ src/pages/blog.xml.js | 19 +++++++++++++ src/pages/blog/[slug].astro | 55 ++++++++++++++++++++++++++++++++++++ src/pages/index.astro | 29 ++++++++++++++++++- 4 files changed, 170 insertions(+), 1 deletion(-) create mode 100644 src/pages/blog.astro create mode 100644 src/pages/blog.xml.js create mode 100644 src/pages/blog/[slug].astro (limited to 'src/pages') diff --git a/src/pages/blog.astro b/src/pages/blog.astro new file mode 100644 index 0000000..4cfcea3 --- /dev/null +++ b/src/pages/blog.astro @@ -0,0 +1,68 @@ +--- +import { getCollection } from "astro:content"; +import Layout from "../layouts/Layout.astro"; +const blogCollection = (await getCollection("blog")).sort((a, b) => { + return b.data.publishedAt.getTime() - a.data.publishedAt.getTime(); +}); +const groupedPosts = blogCollection.reduce( + (acc: Record, post) => { + const year = post.data.publishedAt.getFullYear(); + const month = post.data.publishedAt.getMonth() + 1; + const key = `${year}-${month}`; + if (!acc[key]) { + acc[key] = []; + } + acc[key].push(post); + return acc; + }, + {}, +); +function humaniseDate(date: Date) { + const result = date.toLocaleDateString("es-ES", { + month: "long", + year: "numeric", + }); + return result.charAt(0).toUpperCase() + result.slice(1); +} +const schema = { + "@context": "https://schema.org", + "@type": "Blog", + "headline": "Blog de Ariel Costas", + "description": "En este blog encontrarás artículos sobre desarrollo, tecnología y otras temáticas que pueda querer compartir. Disclaimer de siempre: las opiniones son mías, y no representan a ninguna empresa o institución.", + "publisher": { + "@type": "Person", + "name": "Ariel Costas", + }, + "author": { + "@type": "Person", + "name": "Ariel Costas", + } +}; +--- + + + + +

Blog de Ariel Costas

+ +

+ En este blog encontrarás artículos sobre desarrollo, tecnología y otras + temáticas que pueda querer compartir. Disclaimer de siempre: las + opiniones son mías, y no representan a ninguna empresa o institución. +

+ + { + Object.entries(groupedPosts).map(([key, posts]) => ( +
+

{humaniseDate(new Date(key))}

+ +
+ )) + } +
diff --git a/src/pages/blog.xml.js b/src/pages/blog.xml.js new file mode 100644 index 0000000..b4fbe38 --- /dev/null +++ b/src/pages/blog.xml.js @@ -0,0 +1,19 @@ +import rss from '@astrojs/rss'; +import { getCollection } from 'astro:content'; + + +export async function GET(context) { + const collection = await getCollection('blog'); + + return rss({ + title: "Blog de Ariel Costas", + description: "Artículos del blog de Ariel Costas", + site: context.site, + items: collection.map((post) => ({ + title: post.data.title, + link: `${context.site}blog/${post.slug}`, + description: post.data.metaDescription, + pubDate: post.data.publishedAt + })) + }) +} diff --git a/src/pages/blog/[slug].astro b/src/pages/blog/[slug].astro new file mode 100644 index 0000000..a1a0532 --- /dev/null +++ b/src/pages/blog/[slug].astro @@ -0,0 +1,55 @@ +--- +import type { GetStaticPaths } from "astro"; +import Layout from "../../layouts/Layout.astro"; +import { getCollection } from "astro:content"; +export const getStaticPaths = (async () => { + const entries = await getCollection("blog"); + return entries.map((entry) => ({ + params: { slug: entry.slug }, + props: { entry }, + })); +}) satisfies GetStaticPaths; +const { entry } = Astro.props; +const { Content } = await entry.render(); +const formattedDate = new Date(entry.data.publishedAt).toLocaleDateString( + "es-ES", + { + year: "numeric", + month: "long", + day: "numeric", + weekday: "long", + }, +); +const schema = { + "@context": "https://schema.org", + "@type": "BlogPosting", + headline: entry.data.title, + datePublished: entry.data.publishedAt.toISOString(), + author: { + "@type": "Person", + name: "Ariel Costas Guerrero", + }, + publisher: { + "@type": "Person", + name: "Ariel Costas Guerrero", + logo: { + "@type": "ImageObject", + url: "https://www.costas.dev/favicon.png", + }, + }, +}; +--- + + + + +

{entry.data.title}

+ + Publicado el + + + + +
diff --git a/src/pages/index.astro b/src/pages/index.astro index 0f92a2d..5d1c24d 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -2,6 +2,10 @@ import { getCollection } from "astro:content"; import Layout from "../layouts/Layout.astro"; +const blogCollection = (await getCollection("blog")).sort((a, b) => { + return b.data.publishedAt.getTime() - a.data.publishedAt.getTime(); +}); + const schema = { "@context": "http://schema.org", "@type": "WebSite", @@ -29,6 +33,7 @@ const schema = { su conocimiento. Me gusta la programación, el diseño web y la creatividad. Me encanta crear cosas nuevas y aprender de los demás.

+ Más información sobre mí

¿Qué hago?

@@ -36,6 +41,28 @@ const schema = { Cloud en una empresa de tecnología. Me encargo de desarrollar aplicaciones web en PHP y desplegarlas en la nube de forma segura y eficiente.

- Mi portfolio + +

Últimas entradas del blog

+ + Ver todas las entradas + -- cgit v1.3