MCPcopy Create free account
hub / github.com/adobe/react-spectrum / getTitle

Function getTitle

packages/dev/s2-docs/scripts/generateOGImages.mjs:14–29  ·  view source on GitHub ↗
(filePath)

Source from the content-addressed store, hash-verified

12const outputDir = path.resolve(__dirname, '../dist');
13
14async function getTitle(filePath) {
15 let raw = await fs.readFile(filePath, 'utf8');
16 let parsed = matter(raw);
17 if (parsed.data && parsed.data.title) {
18 return parsed.data.title;
19 }
20 let match = parsed.content.match(/^#\s+(.+)$/m);
21 if (match) {
22 let title = match[1].trim();
23 // Strip out any React components (like <VersionBadge />)
24 title = title.replace(/<[A-Z]\w*[^>]*\/>/g, '').trim();
25 title = title.replace(/<[A-Z]\w*[^>]*>.*?<\/[A-Z]\w*>/g, '').trim();
26 return title;
27 }
28 return path.basename(filePath, path.extname(filePath));
29}
30
31function getSubtitle(slug) {
32 let slugParts = slug.split('/');

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected