diff options
| author | Ariel Costas Guerrero <ariel@costas.dev> | 2025-04-10 21:42:41 +0200 |
|---|---|---|
| committer | Ariel Costas Guerrero <ariel@costas.dev> | 2025-04-10 21:42:41 +0200 |
| commit | e3141794b95e534656427fadf0354435c62254d6 (patch) | |
| tree | 95788249ac51475aea45ad17d7157dffd1564e47 /src/pages/blog | |
| parent | 3caee506c961ae0e78503164ed6a0f81db3c8c32 (diff) | |
Fix formatting
Diffstat (limited to 'src/pages/blog')
| -rw-r--r-- | src/pages/blog/[id].astro | 85 | ||||
| -rw-r--r-- | src/pages/blog/index.astro | 116 |
2 files changed, 109 insertions, 92 deletions
diff --git a/src/pages/blog/[id].astro b/src/pages/blog/[id].astro index e1b5250..65c8a25 100644 --- a/src/pages/blog/[id].astro +++ b/src/pages/blog/[id].astro @@ -4,59 +4,64 @@ import { getCollection, render } from "astro:content"; import { type GetStaticPaths } from "astro"; interface Props { - entry: any; + entry: any; } -export const getStaticPaths: GetStaticPaths = (async () => { - const entries = await getCollection("blog"); - return entries.map((entry: any) => ({ - params: { id: entry.id }, - props: { entry }, - })); -}); +export const getStaticPaths: GetStaticPaths = async () => { + const entries = await getCollection("blog"); + return entries.map((entry: any) => ({ + params: { id: entry.id }, + props: { entry }, + })); +}; const { entry } = Astro.props; const { Content } = await render(entry); const formattedDate = new Date(entry.data.publishedAt).toLocaleDateString( - "es-ES", - { - year: "numeric", - month: "long", - day: "numeric", - weekday: "long", - }, + "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", - }, - }, + "@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", + }, + }, }; --- <Layout title={entry.data.title} description={entry.data.metaDescription}> - <script is:inline type="application/ld+json" slot="head-jsonld" set:html={JSON.stringify(schema)}></script> + <script + is:inline + type="application/ld+json" + slot="head-jsonld" + set:html={JSON.stringify(schema)} + /> - <h1>{entry.data.title}</h1> - <small> - Publicado el - <time datetime={entry.data.publishedAt.toISOString()}> - {formattedDate} - </time> - </small> + <h1>{entry.data.title}</h1> + <small> + Publicado el + <time datetime={entry.data.publishedAt.toISOString()}> + {formattedDate} + </time> + </small> - <Content /> + <Content /> </Layout> diff --git a/src/pages/blog/index.astro b/src/pages/blog/index.astro index e889706..68ad02e 100644 --- a/src/pages/blog/index.astro +++ b/src/pages/blog/index.astro @@ -1,69 +1,81 @@ --- 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(); + return b.data.publishedAt.getTime() - a.data.publishedAt.getTime(); }); + const groupedPosts = blogCollection.reduce( - (acc: Record<string, any[]>, 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; - }, - {}, + (acc: Record<string, any[]>, 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 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", - } + "@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", + }, }; - --- -<Layout title="Blog" description="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."> - <script is:inline type="application/ld+json" slot="head-jsonld" set:html={JSON.stringify(schema)}></script> +<Layout + title="Blog" + description="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." +> + <script + is:inline + type="application/ld+json" + slot="head-jsonld" + set:html={JSON.stringify(schema)} + /> - <h1>Blog de Ariel Costas</h1> + <h1>Blog de Ariel Costas</h1> - <p> - 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. - </p> + <p> + 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. + </p> - { - Object.entries(groupedPosts).map(([key, posts]) => ( - <section> - <h2>{humaniseDate(new Date(key))}</h2> - <ul> - {posts.map((post) => ( - <li> - <a href={`/blog/${post.id}`}>{post.data.title}</a> - </li> - ))} - </ul> - </section> - )) - } + { + Object.entries(groupedPosts).map(([key, posts]) => ( + <section> + <h2>{humaniseDate(new Date(key))}</h2> + <ul> + {posts.map((post) => ( + <li> + <a href={`/blog/${post.id}`}>{post.data.title}</a> + </li> + ))} + </ul> + </section> + )) + } </Layout> |
