From 7b900c2993e1d3fd871299a9ef1d2c6f982e80bb Mon Sep 17 00:00:00 2001 From: Leni Aniva Date: Tue, 5 Nov 2024 11:50:00 -0800 Subject: [PATCH] feat: Read highlighter languages from metadata --- src/content/metadata.json | 9 ++++++++- src/content/post/the-perfect-math-class.md | 4 ++++ svelte.config.js | 15 +++++++++------ 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/content/metadata.json b/src/content/metadata.json index fe4b596..258fb4b 100644 --- a/src/content/metadata.json +++ b/src/content/metadata.json @@ -12,5 +12,12 @@ }, "extra": [ { "route": "/archives", "name": "Archives" } - ] + ], + "markdown": { + "highlighterLangs": [ + "python", + "lean", + "tex" + ] + } } diff --git a/src/content/post/the-perfect-math-class.md b/src/content/post/the-perfect-math-class.md index ce1e00e..d016784 100644 --- a/src/content/post/the-perfect-math-class.md +++ b/src/content/post/the-perfect-math-class.md @@ -26,3 +26,7 @@ $$ $$ \vec z^{(l+1)} = \mat M\vec z^{(l)} + \vec b $$ + +```tex +\\newcommand{\\cirno}{9} +``` diff --git a/svelte.config.js b/svelte.config.js index deabdb8..7fcd4df 100644 --- a/svelte.config.js +++ b/svelte.config.js @@ -1,5 +1,6 @@ import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'; import adapter from '@sveltejs/adapter-static'; +import fs from 'fs'; import { mdsvex, escapeSvelte } from 'mdsvex'; import remarkAlert from './src/lib/markdown.js' @@ -12,7 +13,9 @@ import remarkMath from 'remark-math' const contentDir = process.env?.CHRYSOBLOG_CONTENT ?? "src/content"; -const langs = [ +const metadata = await fs.promises.readFile(contentDir + "/metadata.json") + .then((file) => JSON.parse(file.toString())); +const langs = metadata?.markdown.highlighterLangs ?? [ "javascript", "lean", "lisp", @@ -26,11 +29,7 @@ const langs = [ "c++", "sh", ]; -const highlightingThemes = { - light: 'vitesse-light', - dark: 'vitesse-dark', -}; -const katexOptions = { +const katexOptions = metadata?.markdown.katex ?? { macros: { "\\Nat": "\\mathbb N", "\\Complex": "\\mathbb C", @@ -39,6 +38,10 @@ const katexOptions = { "\\rv": "\\mathrm", }, }; +const highlightingThemes = { + light: 'vitesse-light', + dark: 'vitesse-dark', +}; const themes = Object.keys(highlightingThemes).map(function(k){ return highlightingThemes[k] }); const highlighter = await getHighlighter({