Skip to content

Commit e457db2

Browse files
committed
Show section label on OG cards and guard pages without a card
1 parent 0145ae8 commit e457db2

2 files changed

Lines changed: 22 additions & 8 deletions

File tree

scripts/generateOgImages.mjs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ const CONTENT_DIR = path.join(ROOT, 'src', 'content');
2020
const OUT_DIR = path.join(ROOT, 'public', 'images', 'og');
2121
const CONCURRENCY = 8;
2222

23+
const SECTION_LABELS = {
24+
learn: 'Learn React',
25+
reference: 'API Reference',
26+
community: 'Community',
27+
blog: 'Blog',
28+
};
29+
2330
const bold = fs.readFileSync(
2431
path.join(ROOT, 'public', 'fonts', 'Optimistic_Display_W_Bd.ttf')
2532
);
@@ -32,7 +39,8 @@ function el(type, style, children) {
3239
}
3340

3441
function card(title, pagePath) {
35-
const footer = ('react.dev' + pagePath).toUpperCase();
42+
const section = pagePath.split('/')[1] ?? '';
43+
const label = SECTION_LABELS[section] ?? 'React';
3644
const logo = {
3745
type: 'svg',
3846
props: {
@@ -105,12 +113,11 @@ function card(title, pagePath) {
105113
el(
106114
'div',
107115
{
108-
fontSize: 28,
116+
fontSize: 32,
109117
fontFamily: 'Optimistic Display Medium',
110118
color: '#99a1b3',
111-
letterSpacing: '0.08em',
112119
},
113-
footer
120+
label
114121
),
115122
]
116123
);
@@ -167,6 +174,9 @@ function collectPages(dir, out) {
167174
segments.pop();
168175
}
169176
const pagePath = '/' + segments.join('/');
177+
if (pagePath === '/' || pagePath.startsWith('/errors')) {
178+
continue;
179+
}
170180
const {data} = matter(fs.readFileSync(full, 'utf8'));
171181
const title = data.title ?? sidebarTitles.get(pagePath);
172182
if (title) {

src/components/Layout/Page.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,14 @@ export function Page({
131131
isHomePage={isHomePage}
132132
image={
133133
// OG images are generated per page at build time by
134-
// scripts/generateOgImages.mjs. Error pages have dynamic
135-
// titles, so they keep the static section image.
136-
isHomePage || !title || cleanedPath.startsWith('/errors')
137-
? `/images/og-` + section + '.png'
134+
// scripts/generateOgImages.mjs. Pages without a generated
135+
// card (home, errors, 404, 500) use the static section image.
136+
isHomePage ||
137+
!title ||
138+
cleanedPath.startsWith('/errors') ||
139+
cleanedPath === '/404' ||
140+
cleanedPath === '/500'
141+
? `/images/og-${section ?? 'unknown'}.png`
138142
: `/images/og/${cleanedPath.slice(1).replace(/\//g, '-')}.png`
139143
}
140144
searchOrder={searchOrder}

0 commit comments

Comments
 (0)