Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions website/src/components/features/blog/BlogPost.astro
Original file line number Diff line number Diff line change
Expand Up @@ -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"] & {
Expand All @@ -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,
Expand Down
35 changes: 21 additions & 14 deletions website/src/content.config.ts
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
2 changes: 1 addition & 1 deletion website/src/utils/create-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
27 changes: 27 additions & 0 deletions website/src/utils/resolve-blog-author.ts
Original file line number Diff line number Diff line change
@@ -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;
}