Skip to content

Commit ca492c5

Browse files
committed
fix: build failure and inline og image fonts
1 parent a93080a commit ca492c5

15 files changed

Lines changed: 95 additions & 46 deletions

AGENTS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Commands
2424
Tokens / fonts
2525
- `utils/theme.ts` is the single source for `var(--sc-*)`. Dark overrides in `GlobalStyles.tsx`.
2626
- Display Figtree, body Inter, mono Google Sans Code; injected by next/font as `--font-sans` / `--font-display` / `--font-mono`.
27+
- `next/og` routes cannot use those helpers; fonts come from committed TTFs under `assets/fonts/og/` (`utils/readOgFont.ts`), matching Next.js opengraph-image docs. `test/utils/opengraphImageFonts.spec.ts` guards against CDN font URLs in any `opengraph-image.tsx`.
2728
- Three palette tiers: `lightPalette`, `darkPalette` (CVD-optimized; see theme.ts comments for seeds and pipeline) and the ring colors from `utils/logoPalette.ts`. `theme.palette[N]` auto-switches light/dark. Don't hand-pick oklch; derive from palette indices. Accent variants = L/C shift on the same hue, never adjacent indices.
2829
- OKLCH hue 0° is pink/magenta, not red. See `logoPalette.ts` for the offset that places red at step 0.
2930

app/blog/[slug]/opengraph-image.tsx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { ImageResponse } from 'next/og';
44
import { notFound } from 'next/navigation';
55
import { parser, RuleType, type MarkdownToJSX } from 'markdown-to-jsx';
66
import { getPostBySlug, getPosts } from '@/utils/blog.server';
7+
import { readOgFont } from '@/utils/readOgFont';
78

89
export const alt = 'styled-components blog';
910
const SCALE = 1.5;
@@ -38,12 +39,6 @@ function buildCube(): string {
3839
return `data:image/svg+xml;base64,${Buffer.from(svg).toString('base64')}`;
3940
}
4041

41-
async function fetchFont(url: string): Promise<ArrayBuffer> {
42-
const res = await fetch(url);
43-
if (!res.ok) throw new Error(`font fetch failed (${res.status}): ${url}`);
44-
return res.arrayBuffer();
45-
}
46-
4742
const MONTHS = [
4843
'January',
4944
'February',
@@ -119,9 +114,9 @@ export default async function Image({ params }: { params: Promise<{ slug: string
119114
if (!post) notFound();
120115

121116
const [figtreeBold, inter400, inter600, readMinutes] = await Promise.all([
122-
fetchFont('https://fonts.gstatic.com/s/figtree/v9/_Xmz-HUzqDCFdgfMsYiV_F7wfS-Bs_eYR15e.ttf'),
123-
fetchFont('https://cdn.jsdelivr.net/fontsource/fonts/inter@latest/latin-400-normal.ttf'),
124-
fetchFont('https://cdn.jsdelivr.net/fontsource/fonts/inter@latest/latin-600-normal.ttf'),
117+
readOgFont('figtreeBold'),
118+
readOgFont('interLatin400'),
119+
readOgFont('interLatin600'),
125120
estimateReadTimeMinutes(post),
126121
]);
127122
const twitter = post.authorTwitter;

app/docs/compatibility/opengraph-image.tsx

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ImageResponse } from 'next/og';
2+
import { readOgFont } from '@/utils/readOgFont';
23

34
export const alt = 'React Native CanIUse: CSS feature compatibility for styled-components';
45
const SCALE = 1.5;
@@ -89,18 +90,12 @@ function StatusPill({ status }: { status: Status }) {
8990
);
9091
}
9192

92-
async function fetchFont(url: string): Promise<ArrayBuffer> {
93-
const res = await fetch(url);
94-
if (!res.ok) throw new Error(`font fetch failed (${res.status}): ${url}`);
95-
return res.arrayBuffer();
96-
}
97-
9893
export default async function Image() {
9994
const [figtreeBold, inter400, inter600, mono] = await Promise.all([
100-
fetchFont('https://fonts.gstatic.com/s/figtree/v9/_Xmz-HUzqDCFdgfMsYiV_F7wfS-Bs_eYR15e.ttf'),
101-
fetchFont('https://cdn.jsdelivr.net/fontsource/fonts/inter@latest/latin-400-normal.ttf'),
102-
fetchFont('https://cdn.jsdelivr.net/fontsource/fonts/inter@latest/latin-600-normal.ttf'),
103-
fetchFont('https://cdn.jsdelivr.net/fontsource/fonts/jetbrains-mono@latest/latin-500-normal.ttf'),
95+
readOgFont('figtreeBold'),
96+
readOgFont('interLatin400'),
97+
readOgFont('interLatin600'),
98+
readOgFont('jetbrainsMonoLatin500'),
10499
]);
105100

106101
return new ImageResponse(

app/opengraph-image.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ImageResponse } from 'next/og';
2+
import { readOgFont } from '@/utils/readOgFont';
23

34
export const alt = 'styled-components';
45
export const size = { width: 1200, height: 630 };
@@ -24,9 +25,7 @@ function buildSvg(): string {
2425
}
2526

2627
export default async function Image() {
27-
const figtreeFont = await fetch(
28-
'https://fonts.gstatic.com/s/figtree/v9/_Xmz-HUzqDCFdgfMsYiV_F7wfS-Bs_eYR15e.ttf'
29-
).then(res => res.arrayBuffer());
28+
const figtreeFont = await readOgFont('figtreeBold');
3029

3130
return new ImageResponse(
3231
<div style={{ display: 'flex', width: '100%', height: '100%', background: '#f8f8f8' }}>

assets/fonts/og/NOTICE.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Bundled TTFs used only by next/og ImageResponse (see Next.js opengraph-image docs).
2+
3+
Figtree — SIL Open Font License 1.1 — https://github.com/googlefonts/figtree
4+
Inter — SIL Open Font License 1.1 — https://github.com/rsms/inter
5+
JetBrains Mono — SIL Open Font License 1.1 — https://github.com/JetBrains/JetBrainsMono

assets/fonts/og/figtree-700.ttf

35.3 KB
Binary file not shown.
66.4 KB
Binary file not shown.
66.5 KB
Binary file not shown.
56.1 KB
Binary file not shown.

components/HomepageHeroEditor.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,8 @@ const MobileLatestPost = styled.div`
210210

211211
const DesktopLatestPost = styled.div`
212212
display: flex;
213-
justify-content: flex-end;
214213
width: 100%;
214+
align-self: stretch;
215215
216216
${mobile(css`
217217
display: none;

0 commit comments

Comments
 (0)