From 666349c5b8543382267391618145315270a2bd4c Mon Sep 17 00:00:00 2001
From: grassblock
Date: Sun, 10 Aug 2025 18:37:37 +0800
Subject: [PATCH] feat: display last modified and wordcount on article
---
src/pages/blog/[...slug].astro | 9 ++++++++-
src/plugins/remark/modified-time.mjs | 7 +++----
2 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/src/pages/blog/[...slug].astro b/src/pages/blog/[...slug].astro
index 5396a57..33b9d6e 100644
--- a/src/pages/blog/[...slug].astro
+++ b/src/pages/blog/[...slug].astro
@@ -19,12 +19,16 @@ export async function getStaticPaths() {
}
const { entry } = Astro.props;
-const { Content, headings } = await entry.render();
+const { Content, headings, remarkPluginFrontmatter } = await entry.render();
const noscript = siteConfig.noClientJavaScript
const slug = Astro.params.slug;
const author = Array.isArray(entry.data.author) ? entry.data.author : (entry.data.author !== undefined ? [entry.data.author] : [{collection: 'authors', id: siteConfig.defaultAuthor.id}]);
+// Get Wordcount and Last Updated Date
+const wordcount = remarkPluginFrontmatter.wordcount;
+const lastUpdated = remarkPluginFrontmatter.lastModified;
+
// Get author data
const authorData = await Promise.all((author).map((singleAuthor) => getEntry(singleAuthor).then(authorEntry => authorEntry?.data)))
const authorInfo = authorData.includes(undefined) ? [{data: siteConfig.defaultAuthor}] : authorData;
@@ -53,6 +57,9 @@ const cover = customFeaturedImage || matchedImage_src?.src || firstImageURL || `
{entry.data.title}
{authorInfo.map((a: any) =>
{entry.data.summary}
}