diff --git a/astro/src/layouts/BlogLayout.astro b/astro/src/layouts/BlogLayout.astro index eedfc5ed..4b43de6e 100644 --- a/astro/src/layouts/BlogLayout.astro +++ b/astro/src/layouts/BlogLayout.astro @@ -1,6 +1,6 @@ --- import { getEntry, render } from "astro:content"; -import { getBlogCatalog, type BlogCatalog } from "@lib/blog"; +import { formatAuthorName, getBlogCatalog, type BlogCatalog } from "@lib/blog"; import { getOpenGraphImageData } from "@lib/og-image"; import { isEmpty, kebabCase, startCase } from "lodash-es"; @@ -53,12 +53,6 @@ const metadata: PageMetadata = { ), }; -function formatName(author) { - const { name, cited = undefined } = author.data; - const { first, middle, last } = cited || name; - return [first, middle, last].filter((n) => n).join(" "); -} - const { Content } = await render(blog); import components from "../lib/mdx"; @@ -75,7 +69,7 @@ import ThemedSection from "@components/ThemedSection.astro"; property="article:published_time" content={blog.data.published.toISOString()} /> - + {blog.data.tags.map((tag) => )} @@ -154,7 +148,7 @@ import ThemedSection from "@components/ThemedSection.astro"; {authors.map((author) => (
  • - {formatName(author)} + {formatAuthorName(author)}
  • ))} diff --git a/astro/src/lib/blog.ts b/astro/src/lib/blog.ts index dbc95fe4..51c5d820 100644 --- a/astro/src/lib/blog.ts +++ b/astro/src/lib/blog.ts @@ -1,6 +1,12 @@ import { getCollection, getEntries, type CollectionEntry } from "astro:content"; import { isEmpty, isNil, reverse, sortBy, uniqBy } from "lodash-es"; +export function formatAuthorName(author: CollectionEntry<"staff">): string { + const { name, cited } = author.data; + const { first, middle, last } = cited || name; + return [first, middle, last].filter((n) => n).join(" "); +} + export async function getBlogAuthors( blogs?, ): Promise>> { diff --git a/astro/src/pages/blog/authors/[...slug].astro b/astro/src/pages/blog/authors/[...slug].astro index cb74cba4..306c356e 100644 --- a/astro/src/pages/blog/authors/[...slug].astro +++ b/astro/src/pages/blog/authors/[...slug].astro @@ -1,6 +1,6 @@ --- import { getCollection } from "astro:content"; -import { getBlogAuthors, orderByRecent } from "../../../lib/blog"; +import { formatAuthorName, getBlogAuthors, orderByRecent } from "../../../lib/blog"; import type { Breadcrumbs } from "@lib/types"; import type { CollectionEntry } from "astro:content"; @@ -43,13 +43,13 @@ import BlogLayout from "../../../layouts/BlogLayout.astro"; --- - Blogs by {author.data.name} + Blogs by {formatAuthorName(author)} diff --git a/astro/src/pages/blog/authors/index.astro b/astro/src/pages/blog/authors/index.astro index 75cb340e..71d87aa6 100644 --- a/astro/src/pages/blog/authors/index.astro +++ b/astro/src/pages/blog/authors/index.astro @@ -1,5 +1,5 @@ --- -import { getBlogAuthors } from "../../../lib/blog"; +import { formatAuthorName, getBlogAuthors } from "../../../lib/blog"; const authors = await getBlogAuthors(); const title = "Authors"; @@ -29,7 +29,7 @@ import ThemedSection from "../../../components/ThemedSection.astro"; { authors.map((author) => (
  • - {author.data.name} + {formatAuthorName(author)}
  • )) }