From f51250941f4425ce4d63b90a266a29e8588a7d03 Mon Sep 17 00:00:00 2001
From: Ariel Costas Guerrero
Date: Wed, 30 Apr 2025 08:56:43 +0200
Subject: Add tagging to articles
---
src/pages/blog/[id].astro | 61 +++++++++++
src/pages/blog/index.astro | 265 ++++++++++++++++++++++++++++++++++++++++++---
2 files changed, 312 insertions(+), 14 deletions(-)
(limited to 'src/pages/blog')
diff --git a/src/pages/blog/[id].astro b/src/pages/blog/[id].astro
index 65c8a25..935a796 100644
--- a/src/pages/blog/[id].astro
+++ b/src/pages/blog/[id].astro
@@ -61,7 +61,68 @@ const schema = {
+ {entry.data.tags && entry.data.tags.length > 0 && (
+ <>
+ • Etiquetas:
+
+ >
+ )}
+
+
diff --git a/src/pages/blog/index.astro b/src/pages/blog/index.astro
index 68ad02e..b74781b 100644
--- a/src/pages/blog/index.astro
+++ b/src/pages/blog/index.astro
@@ -6,6 +6,7 @@ const blogCollection = (await getCollection("blog")).sort((a, b) => {
return b.data.publishedAt.getTime() - a.data.publishedAt.getTime();
});
+// Agrupar artículos por fecha
const groupedPosts = blogCollection.reduce(
(acc: Record, post) => {
const year = post.data.publishedAt.getFullYear();
@@ -20,6 +21,9 @@ const groupedPosts = blogCollection.reduce(
{},
);
+// Colección de todas las etiquetas únicas
+const allTags = [...new Set(blogCollection.flatMap(post => post.data.tags || []))].sort();
+
function humaniseDate(date: Date) {
const result = date.toLocaleDateString("es-ES", {
month: "long",
@@ -64,18 +68,251 @@ const schema = {
son mías, y no representan a ninguna empresa o institución.
- {
- Object.entries(groupedPosts).map(([key, posts]) => (
-
+ {
+ Object.entries(groupedPosts).map(([key, posts]) => (
+
+ {humaniseDate(new Date(key))}
+
+ {posts.map((post) => {
+ const postTags = post.data.tags || [];
+ const tagsAttribute = postTags.join(',');
+ return (
+ -
+ {post.data.title}
+ {postTags.length > 0 && (
+
+ {postTags.map((tag: string) => (
+ -
+
+
+ ))}
+
+ )}
+
+ );
+ })}
+
+
+ ))
+ }
+
+
+
+
+
--
cgit v1.3