MCPcopy Create free account
hub / github.com/TanStack/query / addRedirectFromToFileFrontmatter

Function addRedirectFromToFileFrontmatter

scripts/generate-docs.ts:105–125  ·  view source on GitHub ↗
(
  filePath: string,
  fromPaths: Array<string>,
)

Source from the content-addressed store, hash-verified

103}
104
105async 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
127async function addRedirectFromToFrontmatter(
128 outputDir: string,

Callers 1

Calls 1

readFileFunction · 0.85

Tested by

no test coverage detected