2024-09-11 00:51:05 -07:00
|
|
|
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
|
2024-09-19 13:26:56 -07:00
|
|
|
import adapter from '@sveltejs/adapter-static';
|
2024-11-05 11:50:00 -08:00
|
|
|
import fs from 'fs';
|
2024-09-17 13:09:08 -07:00
|
|
|
|
2024-10-15 13:58:14 -07:00
|
|
|
import { mdsvex, escapeSvelte } from 'mdsvex';
|
2024-09-17 13:09:08 -07:00
|
|
|
import remarkAlert from './src/lib/markdown.js'
|
2024-09-17 13:38:18 -07:00
|
|
|
import relativeImages from 'mdsvex-relative-images'
|
2024-09-17 09:40:19 -07:00
|
|
|
import remarkToc from 'remark-toc'
|
|
|
|
import rehypeSlug from 'rehype-slug'
|
2024-10-15 13:58:14 -07:00
|
|
|
import { getHighlighter } from 'shiki'
|
2024-10-16 23:04:12 -07:00
|
|
|
import rehypeKatexSvelte from "rehype-katex-svelte";
|
|
|
|
import remarkMath from 'remark-math'
|
2024-09-11 00:51:05 -07:00
|
|
|
|
2024-09-17 11:38:49 -07:00
|
|
|
const contentDir = process.env?.CHRYSOBLOG_CONTENT ?? "src/content";
|
2024-09-14 18:06:29 -07:00
|
|
|
|
2024-11-05 11:50:00 -08:00
|
|
|
const metadata = await fs.promises.readFile(contentDir + "/metadata.json")
|
|
|
|
.then((file) => JSON.parse(file.toString()));
|
|
|
|
const langs = metadata?.markdown.highlighterLangs ?? [
|
2024-10-15 19:27:40 -07:00
|
|
|
"javascript",
|
|
|
|
"lean",
|
|
|
|
"lisp",
|
2024-10-15 18:59:02 -07:00
|
|
|
"nix",
|
|
|
|
"python",
|
2024-10-15 19:27:40 -07:00
|
|
|
"rust",
|
|
|
|
"toml",
|
2024-10-15 18:59:02 -07:00
|
|
|
"typescript",
|
2024-10-15 19:27:40 -07:00
|
|
|
"yaml",
|
|
|
|
"c",
|
|
|
|
"c++",
|
|
|
|
"sh",
|
2024-10-15 18:59:02 -07:00
|
|
|
];
|
2024-11-05 11:50:00 -08:00
|
|
|
const katexOptions = metadata?.markdown.katex ?? {
|
2024-10-16 23:04:12 -07:00
|
|
|
macros: {
|
|
|
|
"\\Nat": "\\mathbb N",
|
|
|
|
"\\Complex": "\\mathbb C",
|
|
|
|
"\\vec": "\\boldsymbol",
|
|
|
|
"\\mat": "\\boldsymbol",
|
|
|
|
"\\rv": "\\mathrm",
|
|
|
|
},
|
|
|
|
};
|
2024-11-05 11:50:00 -08:00
|
|
|
const highlightingThemes = {
|
|
|
|
light: 'vitesse-light',
|
|
|
|
dark: 'vitesse-dark',
|
|
|
|
};
|
2024-10-15 18:59:02 -07:00
|
|
|
|
2024-10-15 19:27:40 -07:00
|
|
|
const themes = Object.keys(highlightingThemes).map(function(k){ return highlightingThemes[k] });
|
|
|
|
const highlighter = await getHighlighter({
|
|
|
|
themes,
|
|
|
|
langs,
|
|
|
|
})
|
|
|
|
await highlighter.loadLanguage(...langs);
|
|
|
|
|
2024-09-11 00:51:05 -07:00
|
|
|
/** @type {import('@sveltejs/kit').Config} */
|
|
|
|
const config = {
|
|
|
|
// Consult https://kit.svelte.dev/docs/integrations#preprocessors
|
|
|
|
// for more information about preprocessors
|
2024-09-13 21:24:33 -07:00
|
|
|
preprocess: [
|
2024-09-14 00:59:54 -07:00
|
|
|
mdsvex({
|
|
|
|
extensions: ['.md'],
|
2024-09-17 09:40:19 -07:00
|
|
|
remarkPlugins: [
|
|
|
|
remarkAlert,
|
2024-09-17 13:38:18 -07:00
|
|
|
relativeImages,
|
2024-09-17 09:40:19 -07:00
|
|
|
[remarkToc, {tight: true}],
|
2024-10-16 23:04:12 -07:00
|
|
|
remarkMath,
|
2024-09-17 09:40:19 -07:00
|
|
|
],
|
|
|
|
rehypePlugins: [
|
2024-10-16 23:04:12 -07:00
|
|
|
[ rehypeKatexSvelte, katexOptions ],
|
2024-09-17 09:40:19 -07:00
|
|
|
rehypeSlug,
|
2024-10-15 13:58:14 -07:00
|
|
|
],
|
|
|
|
highlight: {
|
|
|
|
highlighter: async (code, lang = 'text') => {
|
2024-10-15 18:59:02 -07:00
|
|
|
const html = escapeSvelte(highlighter.codeToHtml(code, {
|
|
|
|
lang,
|
|
|
|
themes: highlightingThemes,
|
|
|
|
}))
|
2024-10-15 13:58:14 -07:00
|
|
|
return `{@html \`${html}\` }`
|
|
|
|
}
|
|
|
|
},
|
2024-09-17 09:40:19 -07:00
|
|
|
}),
|
2024-09-17 13:09:08 -07:00
|
|
|
vitePreprocess(),
|
2024-09-13 21:24:33 -07:00
|
|
|
],
|
|
|
|
extensions: [".svelte", ".md"],
|
2024-09-11 00:51:05 -07:00
|
|
|
|
|
|
|
kit: {
|
|
|
|
// adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list.
|
|
|
|
// If your environment is not supported, or you settled on a specific environment, switch out the adapter.
|
|
|
|
// See https://kit.svelte.dev/docs/adapters for more information about adapters.
|
2024-09-26 23:02:46 -07:00
|
|
|
adapter: adapter({
|
|
|
|
pages: "build",
|
|
|
|
assets: "build",
|
|
|
|
fallback: null,
|
|
|
|
precompress: false,
|
|
|
|
trailingSlash: 'always',
|
|
|
|
}),
|
2024-09-29 18:45:35 -07:00
|
|
|
prerender: {
|
|
|
|
crawl: true,
|
2024-10-18 10:46:44 -07:00
|
|
|
entries: ['*'],
|
2024-09-29 18:45:35 -07:00
|
|
|
},
|
2024-09-11 07:54:39 -07:00
|
|
|
alias: {
|
2024-09-14 18:06:29 -07:00
|
|
|
$content: contentDir,
|
2024-09-13 21:24:33 -07:00
|
|
|
"@/*": "./*",
|
2024-09-11 07:54:39 -07:00
|
|
|
},
|
2024-09-11 00:51:05 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export default config;
|