mirror of
https://github.com/supabase/supabase.git
synced 2026-07-02 11:44:23 +08:00
strictNullChecks was off for docs, which lets errors slip through and leads to incorrect required/optional typing on Zod-inferred types. This PR enables strictNullChecks and fixes all the existing violations.
52 lines
1.3 KiB
TypeScript
52 lines
1.3 KiB
TypeScript
import { readFile } from 'fs/promises'
|
|
import { processMdx } from '../../helpers.mdx.js'
|
|
import { BaseLoader, BaseSource } from './base.js'
|
|
|
|
export class MarkdownLoader extends BaseLoader {
|
|
type = 'markdown' as const
|
|
|
|
constructor(
|
|
source: string,
|
|
public filePath: string,
|
|
public options?: { yaml?: boolean }
|
|
) {
|
|
const path = filePath.replace(/^(pages|content)/, '').replace(/\.mdx?$/, '')
|
|
super(source, path)
|
|
}
|
|
|
|
async load() {
|
|
const contents = await readFile(this.filePath, 'utf8')
|
|
return [new MarkdownSource(this.source, this.path, contents, this.options)]
|
|
}
|
|
}
|
|
|
|
export class MarkdownSource extends BaseSource {
|
|
type = 'markdown' as const
|
|
|
|
constructor(
|
|
source: string,
|
|
path: string,
|
|
public contents: string,
|
|
public options?: { yaml?: boolean }
|
|
) {
|
|
super(source, path)
|
|
}
|
|
|
|
process() {
|
|
const { checksum, meta, sections } = processMdx(this.contents, this.options)
|
|
|
|
this.checksum = checksum
|
|
this.meta = meta
|
|
this.sections = sections
|
|
|
|
return { checksum, meta, sections }
|
|
}
|
|
|
|
extractIndexedContent(): string {
|
|
const sections = this.sections ?? []
|
|
const sectionText = sections.map(({ content }) => content).join('\n\n')
|
|
|
|
return `# ${this.meta?.title ?? ''}\n\n${this.meta?.subtitle ?? ''}\n\n${sectionText}`
|
|
}
|
|
}
|