diff --git a/website/src/components/features/blog/BlogPost.astro b/website/src/components/features/blog/BlogPost.astro index 1165814..a92de4a 100644 --- a/website/src/components/features/blog/BlogPost.astro +++ b/website/src/components/features/blog/BlogPost.astro @@ -13,6 +13,7 @@ import { JsonLdGraph } from "@/utils/build-json-ld"; import { PEOPLE, isPersonId, personId } from "@/constants/people"; import { getPersonJsonLd } from "@/constants/person-jsonld"; import { organizationJsonLd } from "@/constants/default-jsonld"; +import { resolveTwitterCreator } from "@/utils/resolve-blog-author"; import env from "@/config"; type Props = CollectionEntry<"blog">["data"] & { @@ -34,17 +35,20 @@ const { const currentLocale = getLocaleFromUrl(Astro.url.pathname); const t = await createTranslator(currentLocale); +const blogIndexHref = getLocalizedPath(currentLocale, "/blog"); +const author = authorId && isPersonId(authorId) ? PEOPLE[authorId] : undefined; + const metadata = createMetadata({ title, description, pathname: Astro.url.pathname, imageUrl: heroImage, imageAlt: heroAlt, + twitter: { + creator: resolveTwitterCreator(author?.social.username, tags), + }, }); -const blogIndexHref = getLocalizedPath(currentLocale, "/blog"); -const author = authorId && isPersonId(authorId) ? PEOPLE[authorId] : undefined; - const article: Article = { "@type": "Article", "@id": metadata.canonical as string, diff --git a/website/src/content.config.ts b/website/src/content.config.ts index 21afe7b..3053b77 100644 --- a/website/src/content.config.ts +++ b/website/src/content.config.ts @@ -1,21 +1,28 @@ -import { defineCollection, z } from "astro:content"; +import { defineCollection } from "astro:content"; +import { z } from 'astro/zod' import { glob } from "astro/loaders"; +import { resolveBlogAuthor } from "./utils/resolve-blog-author"; const blog = defineCollection({ loader: glob({ pattern: "**/*.{md,mdx}", base: "./src/contents/blogs" }), - schema: z.object({ - title: z.string(), - description: z.string(), - pubDate: z.coerce.date(), - updatedDate: z.coerce.date().optional(), - heroImage: z.string().optional(), - heroAlt: z.string().optional(), - featured: z.boolean().optional(), - tags: z.array(z.string()).default([]), - author: z - .enum(["christopher-smith", "joe-mattia", "jonathan-angle"]) - .optional(), - }), + schema: z + .object({ + title: z.string(), + description: z.string(), + pubDate: z.coerce.date(), + updatedDate: z.coerce.date().optional(), + heroImage: z.string().optional(), + heroAlt: z.string().optional(), + featured: z.boolean().optional(), + tags: z.array(z.string()).default([]), + author: z + .enum(["christopher-smith", "joe-mattia", "jonathan-angle"]) + .optional(), + }) + .transform((data) => ({ + ...data, + author: resolveBlogAuthor(data.author, data.tags), + })), }); const tocHeadingItem = z.object({ diff --git a/website/src/utils/create-metadata.ts b/website/src/utils/create-metadata.ts index b5fee40..28497ac 100644 --- a/website/src/utils/create-metadata.ts +++ b/website/src/utils/create-metadata.ts @@ -67,7 +67,7 @@ export const createMetadata = ( image: image.url, imageAlt: image.alt, site: "@QuantusNetwork", - creator: "@QuantusNetwork", + creator: seo.twitter?.creator ?? "@QuantusNetwork", card: "summary_large_image", }, canonical, diff --git a/website/src/utils/resolve-blog-author.ts b/website/src/utils/resolve-blog-author.ts new file mode 100644 index 0000000..7390a07 --- /dev/null +++ b/website/src/utils/resolve-blog-author.ts @@ -0,0 +1,27 @@ +export type BlogAuthorId = + | "christopher-smith" + | "joe-mattia" + | "jonathan-angle"; + +export const WEEKLY_UPDATE_TAG = "weekly-update"; +export const WEEKLY_UPDATE_AUTHOR = "christopher-smith" as const; +export const SITE_TWITTER_HANDLE = "@QuantusNetwork"; + +export function resolveTwitterCreator( + authorUsername: string | undefined, + tags: readonly string[], +): string { + if (authorUsername && tags.includes(WEEKLY_UPDATE_TAG)) { + return authorUsername; + } + return SITE_TWITTER_HANDLE; +} + +export function resolveBlogAuthor( + author: BlogAuthorId | undefined, + tags: readonly string[], +): BlogAuthorId | undefined { + if (author) return author; + if (tags.includes(WEEKLY_UPDATE_TAG)) return WEEKLY_UPDATE_AUTHOR; + return undefined; +}