feat: more modern way to use 'reference' to get authors

This commit is contained in:
grassblock 2025-06-06 22:50:36 +08:00
parent 9ff40d1e9e
commit 9ecf25f3ab
4 changed files with 21 additions and 12 deletions

View file

@ -19,10 +19,10 @@ const { entry } = Astro.props;
const { Content } = await entry.render();
const noscript = siteConfig.noClientJavaScript
const slug = Astro.params.slug;
const authorId = entry.data.author || siteConfig.defaultAuthor.id;
const author = entry.data.author || {collection: 'authors', id: siteConfig.defaultAuthor.id};
// Get author data
const authorData = await getEntry('authors', authorId);
const authorData = await getEntry(author);
const authorInfo = authorData ? authorData.data : siteConfig.defaultAuthor;
// get featured image and use it as og:image
@ -46,7 +46,7 @@ const cover = customFeaturedImage || matchedImage_src?.src || firstImageURL || `
author={authorInfo.name}
>
<h1 class="title">{entry.data.title}</h1>
<AuthorInfo id={authorId} />
<AuthorInfo data={authorData} />
<span class="date">{new Date(entry.data.pubDate).toISOString().split('T')[0]}</span>
<div class="content">
<Content />
@ -59,4 +59,5 @@ const cover = customFeaturedImage || matchedImage_src?.src || firstImageURL || `
{noscript && <h2>Comments</h2> <Comments path={`post/${slug}`} />}
</div>
</Layout>
</Layout>

View file

@ -52,7 +52,16 @@ export async function GET(context) {
},
sanitize({ dropElements: ["script", "style"] }),
]);
feedItems.push({ ...post.data, link: `/post/${post.slug}/`, content });
// Make sure each feed item has required properties with proper formatting
feedItems.push({
title: post.data.title,
description: post.data.description || '',
pubDate: post.data.pubDate,
link: `${baseUrl}/post/${post.slug}`,
content,
});
}
// Return our RSS feed XML response.