From b2270003bde65a2bc7aefa9148b14e5502d6ba1f Mon Sep 17 00:00:00 2001 From: grassblock Date: Mon, 11 Aug 2025 17:44:56 +0800 Subject: [PATCH] refactor: move pubDate to date in posts front matter --- src/components/ArticleList.astro | 2 +- src/components/Search.astro | 4 ++-- src/content/posts/_schemas.ts | 3 +-- src/content/posts/first-post/index.md | 2 +- src/content/posts/markdown-example/index.mdx | 6 +++--- src/content/posts/minimalism/index.md | 2 +- src/content/posts/terminal-setup/index.md | 2 +- src/pages/blog.astro | 2 +- src/pages/blog/[...slug].astro | 2 +- src/pages/blog/[...slug].txt.js | 2 +- src/pages/llms.txt.js | 4 ++-- src/pages/rss.xml.js | 4 ++-- src/pages/search-index.json.js | 2 +- src/pages/twtxt.txt.js | 4 ++-- src/plugins/heatmapdata/local.js | 2 +- 15 files changed, 21 insertions(+), 22 deletions(-) diff --git a/src/components/ArticleList.astro b/src/components/ArticleList.astro index f67a2ae..698b205 100644 --- a/src/components/ArticleList.astro +++ b/src/components/ArticleList.astro @@ -4,7 +4,7 @@ const { posts, displayDate = false, placeholder = false } = Astro.props;
{posts.map((post) => (

- {displayDate && {new Date(post.data.pubDate).toISOString().split('T')[0]}} + {displayDate && {new Date(post.data.date).toISOString().split('T')[0]}} {post.data.title}

))} diff --git a/src/components/Search.astro b/src/components/Search.astro index 838d93e..f1a288f 100644 --- a/src/components/Search.astro +++ b/src/components/Search.astro @@ -75,7 +75,7 @@ const domain = Astro.url.host title: string; description?: string; slug?: string; - pubDate?: Date; + date?: Date; searchableTitle: string; searchableDesc: string; searchableContent: string; @@ -199,7 +199,7 @@ const domain = Astro.url.host diff --git a/src/content/posts/_schemas.ts b/src/content/posts/_schemas.ts index 541099f..7408b68 100644 --- a/src/content/posts/_schemas.ts +++ b/src/content/posts/_schemas.ts @@ -5,8 +5,7 @@ export const posts = ({ image }) => z.object({ title: z.string(), description: z.string(), summary: z.string().optional(), - pubDate: z.coerce.date(), - updatedDate: z.coerce.date().optional(), + date: z.coerce.date(), categories: z.array(z.string()).default(['uncategorized']), tags: z.array(z.string()).optional(), cover: image().optional(), diff --git a/src/content/posts/first-post/index.md b/src/content/posts/first-post/index.md index 7ef5f97..7e47cd4 100644 --- a/src/content/posts/first-post/index.md +++ b/src/content/posts/first-post/index.md @@ -1,7 +1,7 @@ --- title: 'First Post' description: 'Welcome to my terminal blog' -pubDate: '2025-06-01' +date: '2025-06-01' --- Hello world! This is the first post on my new terminal blog. diff --git a/src/content/posts/markdown-example/index.mdx b/src/content/posts/markdown-example/index.mdx index 5319c28..f1e9b63 100644 --- a/src/content/posts/markdown-example/index.mdx +++ b/src/content/posts/markdown-example/index.mdx @@ -1,6 +1,6 @@ --- title: "Markdown Syntax Example" -pubDate: '2023-07-15T12:00:00Z' +date: '2023-07-15T12:00:00Z' description: "Sample article showcasing basic Markdown syntax and formatting for HTML elements." tags: ["markdown", "css", "html", "sample"] --- @@ -98,9 +98,9 @@ This most simple one can be used like this: ``` or with a archive link: - + ```mdx - + ``` The `pubDate` or `updatedDate` props is optional, but in order to make the component to display the archived version around the date correctly, they should be passed. diff --git a/src/content/posts/minimalism/index.md b/src/content/posts/minimalism/index.md index cdc32c1..22ea240 100644 --- a/src/content/posts/minimalism/index.md +++ b/src/content/posts/minimalism/index.md @@ -2,7 +2,7 @@ title: 'The Art of Minimalism' description: 'Thoughts on minimalism in design and code' summary: 'Exploring the principles of minimalism and its application in design and coding practices.' -pubDate: '2025-06-05' +date: '2025-06-05' author: 'Wheatley' tags: - 'design' diff --git a/src/content/posts/terminal-setup/index.md b/src/content/posts/terminal-setup/index.md index 63d8d22..3f481e5 100644 --- a/src/content/posts/terminal-setup/index.md +++ b/src/content/posts/terminal-setup/index.md @@ -1,7 +1,7 @@ --- title: 'My Terminal Setup' description: 'A walkthrough of my current terminal configuration' -pubDate: '2025-06-08' +date: '2025-06-08' author: - 'Glados' - 'Wheatley' diff --git a/src/pages/blog.astro b/src/pages/blog.astro index c1d8165..3d9cd35 100644 --- a/src/pages/blog.astro +++ b/src/pages/blog.astro @@ -10,7 +10,7 @@ const lang = getLangFromUrl(Astro.url); const t = useTranslations(lang); const translatePath = useTranslatedPath(lang); const posts = await getCollection('posts'); -posts.sort((a, b) => new Date(b.data.pubDate).getTime() - new Date(a.data.pubDate).getTime()); +posts.sort((a, b) => new Date(b.data.date).getTime() - new Date(a.data.date).getTime()); --- diff --git a/src/pages/blog/[...slug].astro b/src/pages/blog/[...slug].astro index 03c3ff8..623d3a6 100644 --- a/src/pages/blog/[...slug].astro +++ b/src/pages/blog/[...slug].astro @@ -34,7 +34,7 @@ const author = Array.isArray(entry.data.author) ? entry.data.author : (entry.dat const wordcount = remarkPluginFrontmatter.wordcount; const lastUpdated = remarkPluginFrontmatter.lastModified; -const pubDate = new Date(entry.data.pubDate).toISOString().split('T')[0] +const pubDate = new Date(entry.data.date).toISOString().split('T')[0] const lastUpdatedDate = new Date(lastUpdated).toISOString().split('T')[0] // Get author data diff --git a/src/pages/blog/[...slug].txt.js b/src/pages/blog/[...slug].txt.js index 8d5624f..6c90c63 100644 --- a/src/pages/blog/[...slug].txt.js +++ b/src/pages/blog/[...slug].txt.js @@ -11,7 +11,7 @@ export async function GET({ props }) { const { entry } = props; // Format the content as plain text const title = entry.data.title; - const date = entry.data.pubDate.toISOString().split('T')[0]; + const date = entry.data.date.toISOString().split('T')[0]; const content = entry.body; // Combine the post info and body into a single text file diff --git a/src/pages/llms.txt.js b/src/pages/llms.txt.js index 396352b..bdee22c 100644 --- a/src/pages/llms.txt.js +++ b/src/pages/llms.txt.js @@ -19,10 +19,10 @@ ${await generateMarkdownSection("pages", "Page", baseUrl)}`; async function generateMarkdownSection(collectionName, sectionTitle, baseUrl) { const items = await getCollection(collectionName); - // Sort posts by pubDate if available + // Sort posts by date if available const sortedItems = collectionName === "posts" - ? items.sort((a, b) => (a.data.pubDate > b.data.pubDate ? -1 : 1)) + ? items.sort((a, b) => (a.data.date > b.data.date ? -1 : 1)) : items; let markdown = `## ${sectionTitle}\n`; diff --git a/src/pages/rss.xml.js b/src/pages/rss.xml.js index 28a90d4..eb54c16 100644 --- a/src/pages/rss.xml.js +++ b/src/pages/rss.xml.js @@ -23,7 +23,7 @@ export async function GET(context) { // Load the content collection entries to add to our RSS feed. const posts = (await getCollection("posts")).sort((a, b) => // Sort by publication date descending. - a.data.pubDate > b.data.pubDate ? -1 : 1 + a.data.date > b.data.date ? -1 : 1 ); // Loop over blog posts to create feed items for each, including full content. @@ -57,7 +57,7 @@ export async function GET(context) { feedItems.push({ title: post.data.title, description: post.data.description || '', - pubDate: post.data.pubDate, + date: post.data.date, link: `${baseUrl}/blog/${post.slug}`, content, }); diff --git a/src/pages/search-index.json.js b/src/pages/search-index.json.js index 8b91cef..fe24f9f 100644 --- a/src/pages/search-index.json.js +++ b/src/pages/search-index.json.js @@ -6,7 +6,7 @@ export async function GET() { title: post.data.title, description: post.data.description, content: post.body, - pubDate: post.data.pubDate, + date: post.data.date, slug: post.slug })); diff --git a/src/pages/twtxt.txt.js b/src/pages/twtxt.txt.js index 54f6845..6af2c49 100644 --- a/src/pages/twtxt.txt.js +++ b/src/pages/twtxt.txt.js @@ -3,10 +3,10 @@ import { getCollection } from 'astro:content'; export async function GET(context) { const posts = await getCollection('posts'); // Sort posts by date (newest first) - posts.sort((a, b) => new Date(b.data.pubDate).getTime() - new Date(a.data.pubDate).getTime()); + posts.sort((a, b) => new Date(b.data.date).getTime() - new Date(a.data.date).getTime()); const twtxt = posts.map(post => ( - `${new Date(post.data.pubDate).toISOString()}\t${post.data.title} ${context.site}blog/${post.slug}` + `${new Date(post.data.date).toISOString()}\t${post.data.title} ${context.site}blog/${post.slug}` )).join('\n'); return new Response(twtxt, { diff --git a/src/plugins/heatmapdata/local.js b/src/plugins/heatmapdata/local.js index 913b059..0c04586 100644 --- a/src/plugins/heatmapdata/local.js +++ b/src/plugins/heatmapdata/local.js @@ -6,7 +6,7 @@ async function fetchPostsData() { for (const post of posts) { const { remarkPluginFrontmatter } = await post.render(); - const dateKey = post.data.pubDate.toISOString().split('T')[0]; // "2025-07-25" + const dateKey = post.data.date.toISOString().split('T')[0]; // "2025-07-25" entriesData[dateKey] = { wordCount: remarkPluginFrontmatter.wordcount.words / 1000 || 0, link: `/blog/${post.slug}`,