( filePath: string, fromPaths: Array<string>, )
| 103 | } |
| 104 | |
| 105 | async function addRedirectFromToFileFrontmatter( |
| 106 | filePath: string, |
| 107 | fromPaths: Array<string>, |
| 108 | ) { |
| 109 | const markdown = await readFile(filePath, 'utf8') |
| 110 | |
| 111 | const frontmatterMatch = markdown.match(/^---\n([\s\S]*?)\n---\n/) |
| 112 | if (!frontmatterMatch) { |
| 113 | throw new Error(`Expected frontmatter in ${filePath}`) |
| 114 | } |
| 115 | |
| 116 | const redirectLines = fromPaths |
| 117 | .map((fromPath) => ` - ${fromPath}`) |
| 118 | .join('\n') |
| 119 | const updatedFrontmatter = `---\n${frontmatterMatch[1]}\nredirect_from:\n${redirectLines}\n---\n` |
| 120 | |
| 121 | await writeFile( |
| 122 | filePath, |
| 123 | updatedFrontmatter + markdown.slice(frontmatterMatch[0].length), |
| 124 | ) |
| 125 | } |
| 126 | |
| 127 | async function addRedirectFromToFrontmatter( |
| 128 | outputDir: string, |
no test coverage detected