Add support for dynamic authors on blog posts

This commit is contained in:
Tony Grosinger 2023-11-26 10:14:10 -08:00
parent e0de86bb5a
commit 7cad2d9c13
7 changed files with 26 additions and 18 deletions

View File

@ -3,7 +3,7 @@ import Image from 'next/image'
import designSystem from './planetaria-design-system.png' import designSystem from './planetaria-design-system.png'
export const article = { export const article = {
author: 'Adam Wathan', author: 'Tony Grosinger',
date: '2022-09-05', date: '2022-09-05',
title: 'Crafting a design system for a multiplanetary future', title: 'Crafting a design system for a multiplanetary future',
description: description:

View File

@ -1,7 +1,7 @@
import { ArticleLayout } from '@/components/ArticleLayout' import { ArticleLayout } from '@/components/ArticleLayout'
export const article = { export const article = {
author: 'Adam Wathan', author: 'Tony Grosinger',
date: '2022-09-02', date: '2022-09-02',
title: 'Introducing Animaginary: High performance web animations', title: 'Introducing Animaginary: High performance web animations',
description: description:

View File

@ -1,7 +1,7 @@
import { ArticleLayout } from '@/components/ArticleLayout' import { ArticleLayout } from '@/components/ArticleLayout'
export const article = { export const article = {
author: 'Adam Wathan', author: 'Tony Grosinger',
date: '2022-07-14', date: '2022-07-14',
title: 'Rewriting the cosmOS kernel in Rust', title: 'Rewriting the cosmOS kernel in Rust',
description: description:

View File

@ -2,6 +2,18 @@ import assert from 'assert';
import * as cheerio from 'cheerio'; import * as cheerio from 'cheerio';
import { Feed } from 'feed'; import { Feed } from 'feed';
interface Author {
name: string;
email: string;
}
const authors: Record<string, Author> = {
'Tony Grosinger': {
name: 'Tony Grosinger',
email: 'tony@grosinger.net',
},
};
export async function GET(req: Request) { export async function GET(req: Request) {
let siteUrl = process.env.NEXT_PUBLIC_SITE_URL; let siteUrl = process.env.NEXT_PUBLIC_SITE_URL;
@ -9,15 +21,10 @@ export async function GET(req: Request) {
throw Error('Missing NEXT_PUBLIC_SITE_URL environment variable'); throw Error('Missing NEXT_PUBLIC_SITE_URL environment variable');
} }
let author = {
name: 'Spencer Sharp',
email: 'spencer@planetaria.tech',
};
let feed = new Feed({ let feed = new Feed({
title: author.name, title: 'West Sound Community Hall',
description: 'Your blog description', description:
author, 'History, Announcements, and more from the West Sound Hall and Community Club.',
id: siteUrl, id: siteUrl,
link: siteUrl, link: siteUrl,
image: `${siteUrl}/favicon.ico`, image: `${siteUrl}/favicon.ico`,
@ -43,6 +50,7 @@ export async function GET(req: Request) {
let article = $('article').first(); let article = $('article').first();
let title = article.find('h1').first().text(); let title = article.find('h1').first().text();
let date = article.find('time').first().attr('datetime'); let date = article.find('time').first().attr('datetime');
let author = article.find('#byline').first().text().slice(3); // Remove "by " from beginning
let content = article.find('[data-mdx-content]').first().html(); let content = article.find('[data-mdx-content]').first().html();
assert(typeof title === 'string'); assert(typeof title === 'string');
@ -54,8 +62,8 @@ export async function GET(req: Request) {
id: publicUrl, id: publicUrl,
link: publicUrl, link: publicUrl,
content, content,
author: [author], author: [authors[author]],
contributor: [author], contributor: [authors[author]],
date: new Date(date), date: new Date(date),
}); });
} }

View File

@ -7,12 +7,12 @@ import '@/styles/tailwind.css'
export const metadata: Metadata = { export const metadata: Metadata = {
title: { title: {
template: '%s - Spencer Sharp', template: '%s - West Sound Hall',
default: default:
'Spencer Sharp - Software designer, founder, and amateur astronaut', 'West Sound Hall - A community space on Orcas Island',
}, },
description: description:
'Im Spencer, a software designer and entrepreneur based in New York City. Im the founder and CEO of Planetaria, where we develop technologies that empower regular people to explore space on their own terms.', 'WestSound Community Hall, located at 884 Deer Harbor Road in the hamlet of West Sound, has served as a public assembly hall since it was built by volunteers in 1902.',
alternates: { alternates: {
types: { types: {
'application/rss+xml': `${process.env.NEXT_PUBLIC_SITE_URL}/feed.xml`, 'application/rss+xml': `${process.env.NEXT_PUBLIC_SITE_URL}/feed.xml`,

View File

@ -58,6 +58,7 @@ export function ArticleLayout({
<span className="h-4 w-0.5 rounded-full bg-zinc-200 dark:bg-zinc-500" /> <span className="h-4 w-0.5 rounded-full bg-zinc-200 dark:bg-zinc-500" />
<span className="ml-3">{formatDate(article.date)}</span> <span className="ml-3">{formatDate(article.date)}</span>
</time> </time>
<span id="byline" className='mt-4 text-base text-zinc-400 dark:text-zinc-500'>by {article.author}</span>
</header> </header>
<Prose className="mt-8" data-mdx-content> <Prose className="mt-8" data-mdx-content>
{children} {children}

View File

@ -32,8 +32,7 @@ export function Footer() {
<NavLink href="/club">Club</NavLink> <NavLink href="/club">Club</NavLink>
</div> </div>
<p className="text-sm text-zinc-400 dark:text-zinc-500"> <p className="text-sm text-zinc-400 dark:text-zinc-500">
&copy; {new Date().getFullYear()} Spencer Sharp. All rights &copy; {new Date().getFullYear()} West Sound Community Club. All rights reserved.
reserved.
</p> </p>
</div> </div>
</ContainerInner> </ContainerInner>