Something went wrong. Try again.
My website. cameron.stream
Something went wrong. Try again.
TypeScript
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869import { readFileSync } from "node:fs";import { resolve } from "node:path";import matter from "gray-matter";import { z } from "zod";
const CAMERON_DID = process.env.CAMERON_DID || "did:plc:gfrmhdmjvxn2sjedzboeudef";const CONTENT_ROOT = resolve(process.env.PUBLIC_CONTENT_ROOT || resolve(process.cwd(), "content"));const ABOUT_PATH = resolve(CONTENT_ROOT, "about.md");
const aboutFrontmatterSchema = z.object({ title: z.literal("About"), slug: z.literal("about"), updatedAt: z.string().datetime({ offset: true }).optional(), atproto: z.object({ collection: z.literal("stream.cameron.about"), rkey: z.literal("self"), }),});
export type AboutFrontmatter = z.infer<typeof aboutFrontmatterSchema>;
export interface CanonicalAboutSource { file: string; source: string; body: string; frontmatter: AboutFrontmatter;}
export interface AboutDocument { uri: string; body: string; updatedAt?: string;}
let aboutCache: AboutDocument | undefined;const cacheContent = process.env.NODE_ENV === "production";
export function loadCanonicalAboutSource(): CanonicalAboutSource { const raw = readFileSync(ABOUT_PATH, "utf8"); const source = matter(raw); const parsed = aboutFrontmatterSchema.safeParse(source.data); if (!parsed.success) { throw new Error(`about.md: invalid public About frontmatter: ${parsed.error.message}`); } return { file: "about.md", source: raw, body: source.content, frontmatter: parsed.data, };}
export async function getAboutDocument(): Promise<AboutDocument> { if (cacheContent && aboutCache) return aboutCache; const source = loadCanonicalAboutSource(); const front = source.frontmatter; const document = { uri: `at://${CAMERON_DID}/${front.atproto.collection}/${front.atproto.rkey}`, body: source.body.trim(), updatedAt: front.updatedAt, }; if (cacheContent) aboutCache = document; return document;}
export async function getAbout(): Promise<string> { return (await getAboutDocument()).body;}