feat: Cache shiki instance; Add more languages

This commit is contained in:
Leni Aniva 2024-10-15 19:27:40 -07:00
parent 571d54a975
commit ac0d9a5a03
Signed by: aniva
GPG Key ID: 4D9B1C8D10EA4C50
1 changed files with 16 additions and 9 deletions

View File

@ -11,18 +11,31 @@ import { getHighlighter } from 'shiki'
const contentDir = process.env?.CHRYSOBLOG_CONTENT ?? "src/content";
const langs = [
"rust",
"javascript",
"lean",
"lisp",
"nix",
"python",
"lean",
"javascript",
"rust",
"toml",
"typescript",
"yaml",
"c",
"c++",
"sh",
];
const highlightingThemes = {
light: 'vitesse-light',
dark: 'vitesse-dark',
};
const themes = Object.keys(highlightingThemes).map(function(k){ return highlightingThemes[k] });
const highlighter = await getHighlighter({
themes,
langs,
})
await highlighter.loadLanguage(...langs);
/** @type {import('@sveltejs/kit').Config} */
const config = {
// Consult https://kit.svelte.dev/docs/integrations#preprocessors
@ -40,12 +53,6 @@ const config = {
],
highlight: {
highlighter: async (code, lang = 'text') => {
const themes = Object.keys(highlightingThemes).map(function(k){ return highlightingThemes[k] });
const highlighter = await getHighlighter({
themes,
langs,
})
await highlighter.loadLanguage(...langs);
const html = escapeSvelte(highlighter.codeToHtml(code, {
lang,
themes: highlightingThemes,