/** * Mathlified Index Page Server version %version% * generated on %date% */ //@ts-expect-error (this line will be removed during injection) import type { PageServerLoad } from './$types'; import { readFileSync } from 'node:fs'; import path from 'node:path'; export const prerender = true; //@ts-expect-error (this line will be removed during injection) export const load: PageServerLoad = async ({ depends }) => { depends('md'); const filePath = path.join('./src/content/index.md'); const { metadata, body } = extractFrontmatter(readFileSync(filePath, 'utf-8')); let title: string; // 1,2a) prettier workaround: _{} gets converted to \_{}, so we have to change it back in math // 1,2b) go from tex $x$ to $`x` djot syntax // 3) put punctuation in math inline to prevent awkward line breaks // 4) table alignment: prettier-markdown to djot syntax // 5) change $ let content = body .replace(/(? `$$\`${match.replaceAll('\\_', '_')}\``) .replace(/(? `$\`${match.replaceAll('\\_', '_')}\``) .replace(/(? = {}; frontmatter.split('\n').forEach((pair) => { const i = pair.indexOf(':'); metadata[pair.slice(0, i).trim()] = removeQuotes(pair.slice(i + 1).trim()); }); return { metadata, body }; } function removeQuotes(str: string) { return str.replace(/(^["']|["']$)/g, ''); }