Skip to content

Commit 1ff097f

Browse files
authored
[docs-infra] Remove redundant opengraph titles and descriptions (#953)
1 parent 73ea1d0 commit 1ff097f

File tree

9 files changed

+48
-203
lines changed

9 files changed

+48
-203
lines changed

packages/docs-infra/src/createSitemap/types.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,9 @@ export interface SitemapPage {
3838
exports?: Record<string, SitemapExport>;
3939
tags?: string[];
4040
skipDetailSection?: boolean;
41-
openGraph?: {
42-
title?: string;
43-
description?: string;
44-
images?: Array<{
45-
url: string;
46-
width: number;
47-
height: number;
48-
alt: string;
49-
}>;
41+
image?: {
42+
url: string;
43+
alt?: string;
5044
};
5145
}
5246

packages/docs-infra/src/pipeline/syncPageIndex/mergeMetadataMarkdown.test.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -413,20 +413,12 @@ Old description.
413413
{
414414
slug: 'button',
415415
path: './button/page.mdx',
416-
title: 'Button',
417-
description: 'New description with more details.',
416+
title: 'Button Component',
417+
description: 'A comprehensive button component.',
418418
keywords: ['interactive', 'input'],
419-
openGraph: {
420-
title: 'Button Component',
421-
description: 'A comprehensive button component.',
422-
images: [
423-
{
424-
url: 'https://example.com/button.png',
425-
width: 800,
426-
height: 600,
427-
alt: 'Button preview',
428-
},
429-
],
419+
image: {
420+
url: 'https://example.com/button.png',
421+
alt: 'Button preview',
430422
},
431423
},
432424
],

packages/docs-infra/src/pipeline/syncPageIndex/mergeMetadataMarkdown.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,6 @@ export async function mergeMetadataMarkdown(
130130
skipDetailSection: existingPage.skipDetailSection,
131131
// Preserve sections from existing if new doesn't have them
132132
sections: newPage.sections || existingPage.sections,
133-
// Merge openGraph, but ensure description comes from newPage if it has one
134-
openGraph:
135-
newPage.openGraph ??
136-
(newPage.description
137-
? { ...existingPage.openGraph, description: newPage.description }
138-
: existingPage.openGraph),
139133
};
140134
pages.push(merged);
141135
addedPaths.add(newPage.path);

packages/docs-infra/src/pipeline/syncPageIndex/metadataToMarkdown.test.ts

Lines changed: 14 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,9 @@ describe('metadataToMarkdown', () => {
1818
description: 'A button component.',
1919
keywords: ['interactive', 'input'],
2020
embeddings: [0.1, 0.2, 0.3],
21-
openGraph: {
22-
title: 'Button',
23-
description: 'A button component.',
24-
images: [
25-
{
26-
url: 'https://example.com/button.png',
27-
width: 800,
28-
height: 600,
29-
alt: 'A simple button',
30-
},
31-
],
21+
image: {
22+
url: 'https://example.com/button.png',
23+
alt: 'A simple button',
3224
},
3325
},
3426
],
@@ -155,31 +147,6 @@ describe('metadataToMarkdown', () => {
155147
expect(result).not.toContain('Keywords:');
156148
});
157149

158-
it('should prefer openGraph data over regular metadata', () => {
159-
const data: PagesMetadata = {
160-
title: 'Components',
161-
pages: [
162-
{
163-
slug: 'button',
164-
path: './button/page.mdx',
165-
title: 'Regular Button',
166-
description: 'Regular description',
167-
openGraph: {
168-
title: 'OpenGraph Button',
169-
description: 'OpenGraph description',
170-
},
171-
},
172-
],
173-
};
174-
175-
const result = metadataToMarkdown(data);
176-
177-
expect(result).toContain('- [OpenGraph Button](#button) - [Full Docs](./button/page.mdx)');
178-
expect(result).toContain('## OpenGraph Button');
179-
expect(result).not.toContain('Regular Button');
180-
expect(result).not.toContain('Regular description');
181-
});
182-
183150
it('should include description below title', () => {
184151
const data: PagesMetadata = {
185152
title: 'Components',
@@ -353,15 +320,9 @@ describe('metadataToMarkdownAst', () => {
353320
path: './button/page.mdx',
354321
title: 'Button',
355322
description: 'A button component.',
356-
openGraph: {
357-
images: [
358-
{
359-
url: 'https://example.com/button.png',
360-
width: 800,
361-
height: 600,
362-
alt: 'Button image',
363-
},
364-
],
323+
image: {
324+
url: 'https://example.com/button.png',
325+
alt: 'Button image',
365326
},
366327
},
367328
],
@@ -458,8 +419,8 @@ A button component.
458419
expect(page?.description).toBe('A button component.');
459420
expect(page?.keywords).toEqual(['interactive', 'input']);
460421
expect(page?.embeddings).toEqual([0.1, 0.2, 0.3]);
461-
expect(page?.openGraph?.images?.[0].url).toBe('https://example.com/button.png');
462-
expect(page?.openGraph?.images?.[0].alt).toBe('A simple button');
422+
expect(page?.image?.url).toBe('https://example.com/button.png');
423+
expect(page?.image?.alt).toBe('A simple button');
463424
});
464425

465426
it('should parse multiple pages', async () => {
@@ -510,7 +471,7 @@ A button component.
510471

511472
const result = await markdownToMetadata(markdown);
512473

513-
expect(result?.pages[0].openGraph?.images).toBeUndefined();
474+
expect(result?.pages[0]?.image).toBeUndefined();
514475
});
515476

516477
it('should handle pages without keywords', async () => {
@@ -657,7 +618,7 @@ A more detailed button component description.
657618
// Detail section should override editable section
658619
expect(page?.description).toBe('A more detailed button component description.');
659620
expect(page?.keywords).toEqual(['interactive', 'clickable']);
660-
expect(page?.openGraph?.images?.[0].url).toBe('https://example.com/button.png');
621+
expect(page?.image?.url).toBe('https://example.com/button.png');
661622
});
662623

663624
it('should correctly parse actual generated markdown format', async () => {
@@ -1059,17 +1020,9 @@ describe('round-trip conversion', () => {
10591020
description: 'A button component.',
10601021
keywords: ['interactive', 'input'],
10611022
embeddings: [0.1, 0.2, 0.3, 0.4, 0.5],
1062-
openGraph: {
1063-
title: 'Button',
1064-
description: 'A button component.',
1065-
images: [
1066-
{
1067-
url: 'https://example.com/button.png',
1068-
width: 800,
1069-
height: 600,
1070-
alt: 'Button image',
1071-
},
1072-
],
1023+
image: {
1024+
url: 'https://example.com/button.png',
1025+
alt: 'Button image',
10731026
},
10741027
},
10751028
{
@@ -1098,9 +1051,7 @@ describe('round-trip conversion', () => {
10981051
expect(parsed?.pages[0].description).toBe(original.pages[0].description);
10991052
expect(parsed?.pages[0].keywords).toEqual(original.pages[0].keywords);
11001053
expect(parsed?.pages[0].embeddings).toEqual(original.pages[0].embeddings);
1101-
expect(parsed?.pages[0].openGraph?.images?.[0].url).toBe(
1102-
original.pages[0].openGraph?.images?.[0].url,
1103-
);
1054+
expect(parsed?.pages[0].image?.url).toBe(original.pages[0].image?.url);
11041055

11051056
// Check second component
11061057
expect(parsed?.pages[1].slug).toBe(original.pages[1].slug);

packages/docs-infra/src/pipeline/syncPageIndex/metadataToMarkdown.ts

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ export function metadataToMarkdownAst(
458458
// Add page list (editable section) as proper list items
459459
const listItems: any[] = [];
460460
for (const page of pages) {
461-
const pageTitle = page.openGraph?.title || page.title || page.slug;
461+
const pageTitle = page.title || page.slug;
462462

463463
// Check if this is a single-link entry (external link or no detail section)
464464
const isSingleLink = page.skipDetailSection || false;
@@ -516,12 +516,11 @@ export function metadataToMarkdownAst(
516516

517517
// Add detailed page sections (non-editable)
518518
for (const page of pages) {
519-
const pageTitle = page.openGraph?.title || page.title || page.slug;
519+
const pageTitle = page.title || page.slug;
520520
// Note: We don't replace newlines here to allow natural line breaks in detailed sections
521-
const description =
522-
page.openGraph?.description || page.description || 'No description available';
521+
const description = page.description || 'No description available';
523522
const keywords = page.keywords || [];
524-
const image = page.openGraph?.images?.[0];
523+
const image = page.image;
525524

526525
// Add page heading
527526
children.push(heading(2, pageTitle));
@@ -816,7 +815,7 @@ export function metadataToMarkdown(
816815

817816
// Add page list (editable section)
818817
for (const page of pages) {
819-
const pageTitle = page.openGraph?.title || page.title || page.slug;
818+
const pageTitle = page.title || page.slug;
820819

821820
// Check if this is a single-link entry (external link or no detail section)
822821
const isSingleLink = page.skipDetailSection || false;
@@ -869,18 +868,17 @@ export function metadataToMarkdown(
869868
continue;
870869
}
871870

872-
const pageTitle = page.openGraph?.title || page.title || page.slug;
871+
const pageTitle = page.title || page.slug;
873872
// Use descriptionMarkdown to preserve formatting if available
874873
// Note: We don't replace newlines here to allow natural line breaks in detailed sections
875874
let pageDescription: string;
876875
if (page.descriptionMarkdown && page.descriptionMarkdown.length > 0) {
877876
pageDescription = astNodesToMarkdown(page.descriptionMarkdown);
878877
} else {
879-
pageDescription =
880-
page.openGraph?.description || page.description || 'No description available';
878+
pageDescription = page.description || 'No description available';
881879
}
882880
const keywords = page.keywords || [];
883-
const image = page.openGraph?.images?.[0];
881+
const image = page.image;
884882

885883
// Add page heading
886884
lines.push(`## ${pageTitle}`);
@@ -1144,10 +1142,6 @@ export async function markdownToMetadata(markdown: string): Promise<PagesMetadat
11441142
description: 'No description available',
11451143
tags: tags.length > 0 ? tags : undefined,
11461144
skipDetailSection: true, // Mark as external/single-link entry
1147-
openGraph: {
1148-
title: pageTitle,
1149-
description: 'No description available',
1150-
},
11511145
});
11521146
} else if (links.length >= 2) {
11531147
// Two-link format: - [Title](#slug) [Tag1] [Tag2] - [Full Docs](./path/page.mdx)
@@ -1191,10 +1185,6 @@ export async function markdownToMetadata(markdown: string): Promise<PagesMetadat
11911185
title: pageTitle,
11921186
description: 'No description available', // Will be updated from details section
11931187
tags: tags.length > 0 ? tags : undefined,
1194-
openGraph: {
1195-
title: pageTitle,
1196-
description: 'No description available', // Will be updated from details section
1197-
},
11981188
});
11991189
}
12001190
}
@@ -1287,28 +1277,17 @@ export async function markdownToMetadata(markdown: string): Promise<PagesMetadat
12871277
if (paragraphNode.children) {
12881278
currentPage.descriptionMarkdown = stripPositions(paragraphNode.children);
12891279
}
1290-
if (!currentPage.openGraph) {
1291-
currentPage.openGraph = {};
1292-
}
1293-
currentPage.openGraph.description = paragraphText;
12941280
return;
12951281
}
12961282
}
12971283

12981284
// Parse image
12991285
if (currentPage && node.type === 'image') {
13001286
const imageNode = node as ImageNode;
1301-
if (!currentPage.openGraph) {
1302-
currentPage.openGraph = {};
1303-
}
1304-
currentPage.openGraph.images = [
1305-
{
1306-
url: imageNode.url,
1307-
width: 800,
1308-
height: 600,
1309-
alt: imageNode.alt || currentPage.title || currentPage.slug || '',
1310-
},
1311-
];
1287+
currentPage.image = {
1288+
url: imageNode.url,
1289+
alt: imageNode.alt || currentPage.title || currentPage.slug || '',
1290+
};
13121291
return;
13131292
}
13141293
}

packages/docs-infra/src/pipeline/syncPageIndex/syncPageIndex.test.ts

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -221,24 +221,16 @@ Old description.
221221
`);
222222
});
223223

224-
it('should handle metadata with openGraph', async () => {
224+
it('should handle metadata with image', async () => {
225225
const metadata: PageMetadata = {
226226
slug: 'button',
227227
path: './button/page.mdx',
228228
title: 'Button',
229229
description: 'A button component.',
230230
keywords: ['interactive', 'input'],
231-
openGraph: {
232-
title: 'Button Component',
233-
description: 'A comprehensive button component.',
234-
images: [
235-
{
236-
url: 'https://example.com/button.png',
237-
width: 800,
238-
height: 600,
239-
alt: 'Button preview',
240-
},
241-
],
231+
image: {
232+
url: 'https://example.com/button.png',
233+
alt: 'Button preview',
242234
},
243235
};
244236

@@ -256,13 +248,13 @@ Old description.
256248
257249
[//]: # 'This file is autogenerated, but the following list can be modified.'
258250
259-
- [Button Component](#button) - [Full Docs](./button/page.mdx)
251+
- [Button](#button) - [Full Docs](./button/page.mdx)
260252
261253
[//]: # 'This file is autogenerated, DO NOT EDIT AFTER THIS LINE'
262254
263-
## Button Component
255+
## Button
264256
265-
A comprehensive button component.
257+
A button component.
266258
267259
![Button preview](https://example.com/button.png)
268260

0 commit comments

Comments
 (0)