| 12 | const outputDir = path.resolve(__dirname, '../dist'); |
| 13 | |
| 14 | async 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 | |
| 31 | function getSubtitle(slug) { |
| 32 | let slugParts = slug.split('/'); |