diff --git a/src/content.config.ts b/src/content.config.ts index bd52c3b3..2a7cb291 100644 --- a/src/content.config.ts +++ b/src/content.config.ts @@ -12,6 +12,7 @@ const posts = defineCollection({ date: z.coerce.date(), author: z.string().default(DEFAULT_AUTHOR), authorAvatar: z.url().default(DEFAULT_AVATAR), + tags: z.array(z.string()).default([]), cover: z .object({ src: z.url(), diff --git a/src/content/posts/1-21-11.mdx b/src/content/posts/1-21-11.mdx index e92ef7a7..5e330fdf 100644 --- a/src/content/posts/1-21-11.mdx +++ b/src/content/posts/1-21-11.mdx @@ -2,6 +2,9 @@ title: "1.21.11" date: "2025-12-21T20:00:00Z" author: "Paper Team" +tags: + - "updates" + - "paper" --- ## The 1.21.11 Update diff --git a/src/content/posts/1-21.mdx b/src/content/posts/1-21.mdx index 78bd4a8c..da989a67 100644 --- a/src/content/posts/1-21.mdx +++ b/src/content/posts/1-21.mdx @@ -2,6 +2,9 @@ title: "1.21" date: "2024-07-20T18:00:16.000Z" author: "Paper Team" +tags: + - "updates" + - "paper" --- ## The 1.21 Update diff --git a/src/content/posts/welcome-to-papermc.mdx b/src/content/posts/welcome-to-papermc.mdx index 1e162bd0..9d001f41 100644 --- a/src/content/posts/welcome-to-papermc.mdx +++ b/src/content/posts/welcome-to-papermc.mdx @@ -2,6 +2,8 @@ title: "Welcome to PaperMC" date: "2021-12-14T03:36:05.000Z" author: "Paper Team" +tags: + - "paperchan" --- Welcome to PaperMC! diff --git a/src/pages/news/[id].astro b/src/pages/news/[id].astro index 63cd0b29..37f9ddc4 100644 --- a/src/pages/news/[id].astro +++ b/src/pages/news/[id].astro @@ -21,7 +21,7 @@ const mins = minutesToRead(words); const excerpt = truncateForPreview(post.body ?? "", 120); --- - +
@@ -85,6 +85,21 @@ const excerpt = truncateForPreview(post.body ?? "", 120);
{post.data.cover.credit}
) } + + { + post.data.tags && post.data.tags.length > 0 && ( +
+ {post.data.tags.map((tag: string) => ( + + #{tag} + + ))} +
+ ) + }
diff --git a/src/pages/news/index.astro b/src/pages/news/index.astro index 3e2b85fa..254edeb7 100644 --- a/src/pages/news/index.astro +++ b/src/pages/news/index.astro @@ -30,30 +30,47 @@ const postsWithMeta = posts.map((p) => { { postsWithMeta.map((entry, idx) => ( -
+

{entry.data.title}

- {idx === 0 ? ( - - Latest - - ) : null} +
+ {idx === 0 ? ( + + Latest + + ) : null} +
- diff --git a/src/pages/news/tags/[tag].astro b/src/pages/news/tags/[tag].astro new file mode 100644 index 00000000..5cc03ce7 --- /dev/null +++ b/src/pages/news/tags/[tag].astro @@ -0,0 +1,80 @@ +--- +import Layout from "@/layouts/Layout.astro"; +import { getCollection } from "astro:content"; +import { countWords, minutesToRead, truncateForPreview } from "@/utils/content"; +import { formatDateLong } from "@/utils/time.ts"; +import { Icon } from "astro-icon/components"; + +export async function getStaticPaths() { + const allPosts = await getCollection("posts"); + + const uniqueTags = [...new Set(allPosts.map((post: any) => post.data.tags).flat())]; + return uniqueTags.map((tag) => { + const filteredPosts = allPosts.filter((post: any) => post.data.tags.includes(tag)); + const postsWithMeta = filteredPosts.map((p) => { + const words = countWords(p.body ?? ""); + const excerpt = truncateForPreview(p.body ?? "", 512); + return { + ...p, + words, + mins: minutesToRead(words), + excerpt, + }; + }); + return { + params: { tag }, + props: { posts: postsWithMeta }, + }; + }); +} +const { tag } = Astro.params; +const { posts } = Astro.props; +--- + + + + diff --git a/src/pages/news/tags/index.astro b/src/pages/news/tags/index.astro new file mode 100644 index 00000000..d7c9bdaa --- /dev/null +++ b/src/pages/news/tags/index.astro @@ -0,0 +1,35 @@ +--- +import Layout from "@/layouts/Layout.astro"; +import { getCollection } from "astro:content"; +const allPosts = await getCollection("posts"); +const tags = [...new Set(allPosts.map((post: any) => post.data.tags).flat())]; +--- + + +
+
+

Tag Index

+
+ +
+
+ +