|
|
|
|
@ -36,7 +36,10 @@ export async function content() {
|
|
|
|
|
const slug = match[1];
|
|
|
|
|
|
|
|
|
|
const filepath = `${base}/docs/${file}`;
|
|
|
|
|
const markdown = replaceExportTypePlaceholders(await readFile(filepath, 'utf-8'), modules);
|
|
|
|
|
const markdown = await replaceExportTypePlaceholders(
|
|
|
|
|
await readFile(filepath, 'utf-8'),
|
|
|
|
|
modules
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const { body, metadata } = extractFrontmatter(markdown);
|
|
|
|
|
|
|
|
|
|
@ -45,9 +48,9 @@ export async function content() {
|
|
|
|
|
const rank = +metadata.rank || undefined;
|
|
|
|
|
|
|
|
|
|
blocks.push({
|
|
|
|
|
breadcrumbs: [...breadcrumbs, removeMarkdown(remove_TYPE(metadata.title) ?? '')],
|
|
|
|
|
breadcrumbs: [...breadcrumbs, removeMarkdown(metadata.title ?? '')],
|
|
|
|
|
href: get_href([slug]),
|
|
|
|
|
content: plaintext(intro),
|
|
|
|
|
content: await plaintext(intro),
|
|
|
|
|
rank
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
@ -61,13 +64,9 @@ export async function content() {
|
|
|
|
|
const intro = subsections.shift().trim();
|
|
|
|
|
|
|
|
|
|
blocks.push({
|
|
|
|
|
breadcrumbs: [
|
|
|
|
|
...breadcrumbs,
|
|
|
|
|
removeMarkdown(remove_TYPE(metadata.title)),
|
|
|
|
|
remove_TYPE(removeMarkdown(h2))
|
|
|
|
|
],
|
|
|
|
|
breadcrumbs: [...breadcrumbs, removeMarkdown(metadata.title), removeMarkdown(h2)],
|
|
|
|
|
href: get_href([slug, normalizeSlugify(h2)]),
|
|
|
|
|
content: plaintext(intro),
|
|
|
|
|
content: await plaintext(intro),
|
|
|
|
|
rank
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
@ -78,12 +77,12 @@ export async function content() {
|
|
|
|
|
blocks.push({
|
|
|
|
|
breadcrumbs: [
|
|
|
|
|
...breadcrumbs,
|
|
|
|
|
removeMarkdown(remove_TYPE(metadata.title)),
|
|
|
|
|
removeMarkdown(remove_TYPE(h2)),
|
|
|
|
|
removeMarkdown(remove_TYPE(h3))
|
|
|
|
|
removeMarkdown(metadata.title),
|
|
|
|
|
removeMarkdown(h2),
|
|
|
|
|
removeMarkdown(h3)
|
|
|
|
|
],
|
|
|
|
|
href: get_href([slug, normalizeSlugify(h2) + '-' + normalizeSlugify(h3)]),
|
|
|
|
|
content: plaintext(lines.join('\n').trim()),
|
|
|
|
|
content: await plaintext(lines.join('\n').trim()),
|
|
|
|
|
rank
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
@ -93,43 +92,40 @@ export async function content() {
|
|
|
|
|
return blocks;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** @param {string} str */
|
|
|
|
|
function remove_TYPE(str) {
|
|
|
|
|
return str?.replace(/^\[TYPE\]:\s+(.+)/, '$1') ?? '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** @param {string} markdown */
|
|
|
|
|
function plaintext(markdown) {
|
|
|
|
|
async function plaintext(markdown) {
|
|
|
|
|
/** @param {unknown} text */
|
|
|
|
|
const block = (text) => `${text}\n`;
|
|
|
|
|
|
|
|
|
|
/** @param {string} text */
|
|
|
|
|
const inline = (text) => text;
|
|
|
|
|
|
|
|
|
|
return markedTransform(markdown, {
|
|
|
|
|
code: (source) => source.split('// ---cut---\n').pop(),
|
|
|
|
|
blockquote: block,
|
|
|
|
|
html: () => '\n',
|
|
|
|
|
heading: (text) => `${text}\n`,
|
|
|
|
|
hr: () => '',
|
|
|
|
|
list: block,
|
|
|
|
|
listitem: block,
|
|
|
|
|
checkbox: block,
|
|
|
|
|
paragraph: (text) => `${text}\n\n`,
|
|
|
|
|
table: block,
|
|
|
|
|
tablerow: block,
|
|
|
|
|
tablecell: (text, opts) => {
|
|
|
|
|
return text + ' ';
|
|
|
|
|
},
|
|
|
|
|
strong: inline,
|
|
|
|
|
em: inline,
|
|
|
|
|
codespan: inline,
|
|
|
|
|
br: () => '',
|
|
|
|
|
del: inline,
|
|
|
|
|
link: (href, title, text) => text,
|
|
|
|
|
image: (href, title, text) => text,
|
|
|
|
|
text: inline
|
|
|
|
|
})
|
|
|
|
|
return (
|
|
|
|
|
await markedTransform(markdown, {
|
|
|
|
|
code: (source) => source.split('// ---cut---\n').pop(),
|
|
|
|
|
blockquote: block,
|
|
|
|
|
html: () => '\n',
|
|
|
|
|
heading: (text) => `${text}\n`,
|
|
|
|
|
hr: () => '',
|
|
|
|
|
list: block,
|
|
|
|
|
listitem: block,
|
|
|
|
|
checkbox: block,
|
|
|
|
|
paragraph: (text) => `${text}\n\n`,
|
|
|
|
|
table: block,
|
|
|
|
|
tablerow: block,
|
|
|
|
|
tablecell: (text, opts) => {
|
|
|
|
|
return text + ' ';
|
|
|
|
|
},
|
|
|
|
|
strong: inline,
|
|
|
|
|
em: inline,
|
|
|
|
|
codespan: inline,
|
|
|
|
|
br: () => '',
|
|
|
|
|
del: inline,
|
|
|
|
|
link: (href, title, text) => text,
|
|
|
|
|
image: (href, title, text) => text,
|
|
|
|
|
text: inline
|
|
|
|
|
})
|
|
|
|
|
)
|
|
|
|
|
.replace(/</g, '<')
|
|
|
|
|
.replace(/>/g, '>')
|
|
|
|
|
.replace(/&#(\d+);/g, (match, code) => {
|
|
|
|
|
|