From 1e7f0f9e4a97903b8624f9becdf411a3e84f8c22 Mon Sep 17 00:00:00 2001 From: grassblock Date: Wed, 28 May 2025 17:33:09 +0800 Subject: [PATCH] feat: added author info in article page --- src/components/helper/authors/Info.astro | 29 ++++++++++++++++++++++++ src/config.ts | 2 ++ src/pages/post/[...slug].astro | 2 ++ 3 files changed, 33 insertions(+) create mode 100644 src/components/helper/authors/Info.astro diff --git a/src/components/helper/authors/Info.astro b/src/components/helper/authors/Info.astro new file mode 100644 index 0000000..806a143 --- /dev/null +++ b/src/components/helper/authors/Info.astro @@ -0,0 +1,29 @@ +--- +import {Image} from "astro:assets"; +import {getEntry} from "astro:content"; +import {siteConfig} from "../../../config"; + +const { id } = Astro.props; + +// Get author data +const authorData = await getEntry('authors', id || ''); +const authorAvatar = authorData?.data.mcplayerid ? `/images/avatars/${id}.png` : null; +const authorName = authorData ? authorData.data.name : null; +--- +{(siteConfig.displayAvatar && authorData) && + <> + {authorAvatar && {`avatar} + {authorName} @ + + } + \ No newline at end of file diff --git a/src/config.ts b/src/config.ts index 709cb5d..c5618a8 100644 --- a/src/config.ts +++ b/src/config.ts @@ -26,6 +26,8 @@ export const siteConfig = { // search // This only works when noClientJavaScript is enabled searchEngine: 'bing', // 'google', 'duckduckgo', 'bing'(broken until M1cr0$0ft get support for it), defaults to 'google' + // content + displayAvatar: true, // display author avatar in the article list and info line of article page // footer // yes you can write html safely here customFooter: 'I have no mouth, and I must SCREAM', diff --git a/src/pages/post/[...slug].astro b/src/pages/post/[...slug].astro index ae5d4db..e430eed 100644 --- a/src/pages/post/[...slug].astro +++ b/src/pages/post/[...slug].astro @@ -6,6 +6,7 @@ import {getImage} from "astro:assets"; import {siteConfig} from "../../config"; import ReplyViaEmail from "../../components/ReplyViaEmail.astro"; import { ExtractFirstImage } from '../../plugins/extract-images'; +import AuthorInfo from "../../components/helper/authors/Info.astro"; export async function getStaticPaths() { const blogEntries = await getCollection('posts'); @@ -45,6 +46,7 @@ const cover = customFeaturedImage || matchedImage_src?.src || firstImageURL || ` author={authorInfo.name} >

{entry.data.title}

+ {new Date(entry.data.pubDate).toISOString().split('T')[0]}