MCPcopy Create free account
hub / github.com/arktypeio/arktype / writeMarkdown

Function writeMarkdown

ark/docs/lib/writeMarkdown.ts:49–96  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

47 * - the skill's references/migrating.md, from /docs/migrating
48 */
49export const writeMarkdown = (): void => {
50 const tree = getPageTree()
51 rmSync(join(publicDir, "docs"), { recursive: true, force: true })
52
53 const markdownByUrl = new Map<string, string>()
54 for (const page of tree.pages) {
55 const { frontmatter, body } = parseMdx(readFileSync(page.path, "utf8"))
56 let markdown: string
57 try {
58 markdown = mdxToMarkdown(frontmatter, body)
59 } catch (e) {
60 throw new Error(`Failed to write ${page.url}.md`, { cause: e })
61 }
62 markdownByUrl.set(page.url, markdown)
63 write(join(publicDir, `${page.url}.md`), markdown)
64 }
65
66 for (const [from, to] of Object.entries(redirects)) {
67 // /docs.md would land outside the directory cleared above
68 if (!from.startsWith("/docs/")) continue
69 const target = tree.pageByUrl.get(to.replace(/#.*$/, ""))!
70 write(
71 join(publicDir, `${from}.md`),
72 `# Moved\n\n> This page is now [${target.frontmatter.title}](${siteUrl}${target.url}.md).\n`
73 )
74 }
75
76 const sections = tree.sections.filter(section => section.id in fullFiles)
77 for (const section of sections) {
78 write(
79 join(publicDir, fullFiles[section.id]),
80 [
81 `# ${section.title}`,
82 `> ${section.description}`,
83 ...section.pages.map(page =>
84 // a link to a heading on its own page is ambiguous among every page
85 markdownByUrl
86 .get(page.url)!
87 .trim()
88 .replaceAll("](#", `](${siteUrl}${page.url}#`)
89 )
90 ].join("\n\n") + "\n"
91 )
92 }
93
94 write(join(publicDir, "llms.txt"), llmsIndex(sections))
95 writeSkillMigrating(markdownByUrl.get("/docs/migrating")!)
96}
97
98/** formatted as the repo formats Markdown, since the skill is checked in */
99const writeSkillMigrating = (page: string) => {

Callers 1

next.config.tsFile · 0.90

Calls 12

getPageTreeFunction · 0.90
parseMdxFunction · 0.90
mdxToMarkdownFunction · 0.90
joinFunction · 0.85
llmsIndexFunction · 0.85
writeSkillMigratingFunction · 0.85
replaceMethod · 0.80
filterMethod · 0.80
writeFunction · 0.70
getMethod · 0.65
mapMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected