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
3 changes: 2 additions & 1 deletion src/components/BaseHead.astro
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ interface Props {

import { withBase } from "../lib/utils";
const { title, description = "The official blog of the Python core development team.", image } = Astro.props;
const baseUrl = import.meta.env.DEV ? Astro.url.origin : Astro.site;
const canonicalURL = new URL(Astro.url.pathname, Astro.site);
const ogImage = image ? new URL(image, Astro.site) : new URL(withBase("/og-default.png"), Astro.site);
const ogImage = image ? new URL(image, baseUrl) : new URL(withBase("/og-default.png"), baseUrl);
---

<meta charset="utf-8" />
Expand Down
23 changes: 23 additions & 0 deletions src/lib/og-fonts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Shared font loading for OG image generation
async function loadFont(weight: number): Promise<ArrayBuffer> {
const url = `https://fonts.googleapis.com/css2?family=Inter:wght@${weight}&display=swap`;
const css = await fetch(url).then((r) => r.text());
const match = css.match(/src: url\((.+?)\) format/);
if (!match?.[1]) throw new Error(`Failed to load Inter ${weight}`);
return fetch(match[1]).then((r) => r.arrayBuffer());
}

let fontsPromise: Promise<
{ name: string; data: ArrayBuffer; weight: 400 | 600 | 700; style: "normal" }[]
> | null = null;

export function getFonts() {
if (!fontsPromise) {
fontsPromise = Promise.all([
loadFont(400).then((data) => ({ name: "Inter" as const, data, weight: 400 as const, style: "normal" as const })),
loadFont(600).then((data) => ({ name: "Inter" as const, data, weight: 600 as const, style: "normal" as const })),
loadFont(700).then((data) => ({ name: "Inter" as const, data, weight: 700 as const, style: "normal" as const })),
]);
}
return fontsPromise;
Comment on lines +10 to +22
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fontsPromise is declared as Promise<...> | null, so getFonts() currently returns a nullable type. Even though the implementation always initializes the promise before returning, the nullable return type can leak into callers and allow null to be passed to satori without a type error. Consider changing this to let fontsPromise: Promise<...> | undefined (or similar) and having getFonts() explicitly return Promise<...> (non-nullable).

Copilot uses AI. Check for mistakes.
}
Loading