2023-06-01 01:09:44 +00:00
|
|
|
import adapter from '@sveltejs/adapter-auto';
|
|
|
|
import { vitePreprocess } from '@sveltejs/kit/vite';
|
2023-07-01 00:38:42 +00:00
|
|
|
import {mdsvex} from "mdsvex";
|
|
|
|
|
|
|
|
function escapeBraces(unsafe)
|
|
|
|
{
|
|
|
|
return unsafe
|
|
|
|
.replace(/{/g, "{")
|
|
|
|
.replace(/}/g, "}");
|
|
|
|
}
|
|
|
|
|
|
|
|
function highlighter(code, lang) {
|
|
|
|
// Lang can be:
|
|
|
|
// just the lang ('rust')
|
|
|
|
// the lang, then in brackets lines to hightlight ('rust[1-5,9,21-23]')
|
|
|
|
|
|
|
|
let params = new URLSearchParams(lang.split('?')[1]);
|
|
|
|
let real_lang = lang.split('?')[0];
|
|
|
|
|
|
|
|
let classes = [`language-${real_lang}`];
|
|
|
|
let props = "";
|
|
|
|
|
|
|
|
if (params.has("lines")) {
|
|
|
|
props += `data-line="${params.get("lines")}" `;
|
|
|
|
}
|
|
|
|
if (params.has("src")) {
|
|
|
|
props += `data-src="${params.get("src")}" `;
|
|
|
|
}
|
|
|
|
if (params.has("enableDownload")) {
|
|
|
|
props += "data-download-link ";
|
|
|
|
}
|
|
|
|
if (params.has("downloadLabel")) {
|
|
|
|
props += `data-download-link-label="${params.get("downloadLabel")}" `;
|
|
|
|
}
|
|
|
|
|
|
|
|
return `<pre class="rainbow-braces diff-highlight line-numbers match-braces ${classes}" ${props}><code class="language-${real_lang}" ${props}>${escapeBraces(code)}</code></pre>`
|
|
|
|
}
|
2023-06-01 01:09:44 +00:00
|
|
|
|
|
|
|
/** @type {import('@sveltejs/kit').Config} */
|
|
|
|
const config = {
|
|
|
|
// Consult https://kit.svelte.dev/docs/integrations#preprocessors
|
|
|
|
// for more information about preprocessors
|
2023-07-01 00:38:42 +00:00
|
|
|
preprocess: [
|
|
|
|
vitePreprocess(),
|
|
|
|
mdsvex({
|
|
|
|
extensions: ['.svx'],
|
|
|
|
layout: './src/lib/PostLayout.svelte',
|
|
|
|
highlight: {
|
|
|
|
highlighter
|
|
|
|
}
|
|
|
|
})
|
|
|
|
],
|
|
|
|
|
|
|
|
extensions: ['.svelte', '.svx'],
|
2023-06-01 01:09:44 +00: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.
|
|
|
|
adapter: adapter(),
|
|
|
|
alias: {
|
|
|
|
"$components": "src/components"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export default config;
|