import path from 'node:path' import { globby } from 'globby' export type FrontmatterFormat = 'yaml' | 'toml' export interface MarkdownSource { sourceFile: string slug: string outPath: string frontmatter: FrontmatterFormat /** * `mdx` runs the file through the MDX-to-markdown pipeline. `raw` copies the * body after frontmatter as-is: AI prompts are plain markdown written for * agents, and text such as `` in them is not valid MDX. */ kind: 'mdx' | 'raw' } const OUTPUT_ROOT = 'public/markdown/guides' const GUIDES_GLOB = 'content/guides/**/!(_)*.mdx' // Read from the repo root rather than the copy codegen:examples makes, so this // task doesn't depend on that one having run. const PROMPTS_GLOB = '../../examples/prompts/*.md' export function guideSlug(sourceFile: string): string { return sourceFile.replace(/^content\/guides\//, '').replace(/\.mdx$/, '') } export function promptSlug(sourceFile: string): string { return `ai-tools/ai-prompts/${path.basename(sourceFile, '.md')}` } export async function collectMarkdownSources(): Promise { const [guideFiles, promptFiles] = await Promise.all([ globby([GUIDES_GLOB]), globby([PROMPTS_GLOB]), ]) const guides: MarkdownSource[] = guideFiles.map((sourceFile) => { const slug = guideSlug(sourceFile) return { sourceFile, slug, outPath: `${OUTPUT_ROOT}/${slug}.md`, frontmatter: 'yaml', kind: 'mdx', } }) const prompts: MarkdownSource[] = promptFiles.map((sourceFile) => { const slug = promptSlug(sourceFile) return { sourceFile, slug, outPath: `${OUTPUT_ROOT}/${slug}.md`, frontmatter: 'yaml', kind: 'raw', } }) return [...guides, ...prompts] }