Files
supabase/apps/docs/internals/markdown-sources.ts
2026-07-13 09:05:36 -07:00

48 lines
1.4 KiB
TypeScript

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
}
const OUTPUT_ROOT = 'public/markdown/guides'
const GUIDES_GLOB = 'content/guides/**/!(_)*.mdx'
const TROUBLESHOOTING_GLOB = 'content/troubleshooting/!(_)*.mdx'
export function guideSlug(sourceFile: string): string {
return sourceFile.replace(/^content\/guides\//, '').replace(/\.mdx$/, '')
}
export function troubleshootingSlug(sourceFile: string): string {
return `troubleshooting/${path.basename(sourceFile, '.mdx')}`
}
export interface MarkdownSources {
guides: MarkdownSource[]
troubleshooting: MarkdownSource[]
}
export async function collectMarkdownSources(): Promise<MarkdownSources> {
const [guideFiles, troubleshootingFiles] = await Promise.all([
globby([GUIDES_GLOB]),
globby([TROUBLESHOOTING_GLOB]),
])
const guides: MarkdownSource[] = guideFiles.map((sourceFile) => {
const slug = guideSlug(sourceFile)
return { sourceFile, slug, outPath: `${OUTPUT_ROOT}/${slug}.md`, frontmatter: 'yaml' }
})
const troubleshooting: MarkdownSource[] = troubleshootingFiles.map((sourceFile) => {
const slug = troubleshootingSlug(sourceFile)
return { sourceFile, slug, outPath: `${OUTPUT_ROOT}/${slug}.md`, frontmatter: 'toml' }
})
return { guides, troubleshooting }
}