Chrysoblog/svelte.config.js

107 lines
2.9 KiB
JavaScript
Raw Normal View History

2024-09-11 00:51:05 -07:00
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
import adapter from '@sveltejs/adapter-static';
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'
import relativeImages from 'mdsvex-relative-images'
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
const contentDir = process.env?.CHRYSOBLOG_CONTENT ?? "src/content";
2024-09-14 18:06:29 -07:00
const metadata = await fs.promises.readFile(contentDir + "/metadata.json")
.then((file) => JSON.parse(file.toString()));
const langs = metadata?.markdown.highlighterLangs ?? [
"javascript",
"lean",
"lisp",
2024-10-15 18:59:02 -07:00
"nix",
"python",
"rust",
"toml",
2024-10-15 18:59:02 -07:00
"typescript",
"yaml",
"c",
"c++",
"sh",
2024-10-15 18:59:02 -07: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",
},
};
const highlightingThemes = {
light: 'vitesse-light',
dark: 'vitesse-dark',
};
2024-10-15 18:59:02 -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
preprocess: [
2024-09-14 00:59:54 -07:00
mdsvex({
extensions: ['.md'],
remarkPlugins: [
remarkAlert,
relativeImages,
[remarkToc, {tight: true}],
2024-10-16 23:04:12 -07:00
remarkMath,
],
rehypePlugins: [
2024-10-16 23:04:12 -07:00
[ rehypeKatexSvelte, katexOptions ],
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 13:09:08 -07:00
vitePreprocess(),
],
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-11 07:54:39 -07:00
},
2024-09-11 00:51:05 -07:00
}
};
export default config;