feat: multi-authors within one article support
This commit is contained in:
parent
0eef3d8d05
commit
98d23e7c94
4 changed files with 14 additions and 12 deletions
|
@ -1,18 +1,17 @@
|
||||||
---
|
---
|
||||||
import {Image} from "astro:assets";
|
import {Image} from "astro:assets";
|
||||||
import {getEntry} from "astro:content";
|
|
||||||
import {siteConfig} from "../../../config";
|
import {siteConfig} from "../../../config";
|
||||||
|
|
||||||
const { data } = Astro.props;
|
const { data } = Astro.props;
|
||||||
|
|
||||||
// Get author data
|
// Get author data
|
||||||
const authorAvatar = data?.data.mcplayerid ? `/images/avatars/${data.id}.png` : null;
|
const authorAvatar = data.mcplayerid ? `/images/avatars/${data.mcplayerid}.png` : null;
|
||||||
const authorName = data ? data.data.name : null;
|
const authorName = data.name ? data.name : null;
|
||||||
---
|
---
|
||||||
{(siteConfig.displayAvatar && data) &&
|
{(siteConfig.displayAvatar && data) &&
|
||||||
<>
|
<>
|
||||||
{authorAvatar && <Image src={authorAvatar} alt={`avatar of ${authorName}`} width=16 height=16 />}
|
{authorAvatar && <Image src={authorAvatar} alt={`avatar of ${authorName}`} width=16 height=16 />}
|
||||||
<span>{authorName} @ </span>
|
<span>{authorName}</span> |
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
<style>
|
<style>
|
||||||
|
|
|
@ -10,5 +10,5 @@ export const posts = ({ image }) => z.object({
|
||||||
categories: z.array(z.string()).default(['uncategorized']),
|
categories: z.array(z.string()).default(['uncategorized']),
|
||||||
tags: z.array(z.string()).optional(),
|
tags: z.array(z.string()).optional(),
|
||||||
cover: image().optional(),
|
cover: image().optional(),
|
||||||
author: reference('authors').optional(),
|
author: z.union([z.array(reference('authors')), reference('authors')]).optional(),
|
||||||
});
|
});
|
|
@ -2,6 +2,9 @@
|
||||||
title: 'My Terminal Setup'
|
title: 'My Terminal Setup'
|
||||||
description: 'A walkthrough of my current terminal configuration'
|
description: 'A walkthrough of my current terminal configuration'
|
||||||
pubDate: '2025-06-08'
|
pubDate: '2025-06-08'
|
||||||
|
author:
|
||||||
|
- 'Glados'
|
||||||
|
- 'Wheatley'
|
||||||
---
|
---
|
||||||

|

|
||||||
Here's my current terminal setup:
|
Here's my current terminal setup:
|
||||||
|
|
|
@ -23,11 +23,11 @@ const { Content, headings } = await entry.render();
|
||||||
|
|
||||||
const noscript = siteConfig.noClientJavaScript
|
const noscript = siteConfig.noClientJavaScript
|
||||||
const slug = Astro.params.slug;
|
const slug = Astro.params.slug;
|
||||||
const author = entry.data.author || {collection: 'authors', id: siteConfig.defaultAuthor.id};
|
const author = Array.isArray(entry.data.author) ? entry.data.author : (entry.data.author !== undefined ? [entry.data.author] : [{collection: 'authors', id: siteConfig.defaultAuthor.id}]);
|
||||||
|
|
||||||
// Get author data
|
// Get author data
|
||||||
const authorData = await getEntry(author);
|
const authorData = await Promise.all((author).map((singleAuthor) => getEntry(singleAuthor).then(authorEntry => authorEntry.data)))
|
||||||
const authorInfo = authorData ? authorData.data : siteConfig.defaultAuthor;
|
const authorInfo = authorData.includes(undefined) ? [{data: siteConfig.defaultAuthor}] : authorData;
|
||||||
|
|
||||||
// get featured image and use it as og:image
|
// get featured image and use it as og:image
|
||||||
// use the custom cover image if it exists, otherwise use the featured image file in the same directory
|
// use the custom cover image if it exists, otherwise use the featured image file in the same directory
|
||||||
|
@ -36,7 +36,7 @@ const customFeaturedImage = entry.data.cover?.src
|
||||||
const matchedImage = Object.keys(featuredImages).find(path => path.includes(slug));
|
const matchedImage = Object.keys(featuredImages).find(path => path.includes(slug));
|
||||||
let matchedImage_src;
|
let matchedImage_src;
|
||||||
if (matchedImage && !customFeaturedImage) {
|
if (matchedImage && !customFeaturedImage) {
|
||||||
matchedImage_src = await getImage({src: featuredImages[matchedImage], format: 'webp'}) || null;
|
matchedImage_src = await getImage({src: featuredImages[matchedImage] as ImageMetadata, format: 'webp'}) || null;
|
||||||
}
|
}
|
||||||
const firstImageURL = await ExtractFirstImage(Content)
|
const firstImageURL = await ExtractFirstImage(Content)
|
||||||
|
|
||||||
|
@ -47,10 +47,10 @@ const cover = customFeaturedImage || matchedImage_src?.src || firstImageURL || `
|
||||||
title={entry.data.title}
|
title={entry.data.title}
|
||||||
description={entry.data.description}
|
description={entry.data.description}
|
||||||
ogImage={cover}
|
ogImage={cover}
|
||||||
author={authorInfo.name}
|
author={authorInfo.map((a: any) => a.name).join(', ')}
|
||||||
>
|
>
|
||||||
<h1 class="title">{entry.data.title}</h1>
|
<h1 class="title">{entry.data.title}</h1>
|
||||||
<AuthorInfo data={authorData} />
|
{authorInfo.map((a: any) => <AuthorInfo data={a} />)}
|
||||||
<span class="date">{new Date(entry.data.pubDate).toISOString().split('T')[0]}</span>
|
<span class="date">{new Date(entry.data.pubDate).toISOString().split('T')[0]}</span>
|
||||||
{headings.length !== 0 && <TableOfContents headings={headings} />}
|
{headings.length !== 0 && <TableOfContents headings={headings} />}
|
||||||
{entry.data.summary && <p class="summary">{entry.data.summary}</p> }
|
{entry.data.summary && <p class="summary">{entry.data.summary}</p> }
|
||||||
|
@ -59,7 +59,7 @@ const cover = customFeaturedImage || matchedImage_src?.src || firstImageURL || `
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="extra-post" style="margin-top: 2rem; border-top: 1px solid var(--border-color); padding-top: 1rem;">
|
<div class="extra-post" style="margin-top: 2rem; border-top: 1px solid var(--border-color); padding-top: 1rem;">
|
||||||
<ReplyViaEmail title={entry.data.title} email={authorInfo.email} />
|
<ReplyViaEmail title={entry.data.title} email={authorInfo[0].email} />
|
||||||
<br>
|
<br>
|
||||||
<a href="/blog">← Back to posts</a>
|
<a href="/blog">← Back to posts</a>
|
||||||
{!noscript && <h2>Comments</h2> <Comments />}
|
{!noscript && <h2>Comments</h2> <Comments />}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue