feat: use syntax highlight assets on server #14

Manually merged
sup39 merged 1 commit from feat/prism-local-assets into main 2024-01-25 12:37:04 +09:00
2 changed files with 4 additions and 5 deletions

View file

@ -0,0 +1 @@
../../node_modules/prismjs/components

View file

@ -2,15 +2,13 @@ import Prism from "prismjs";
import "prismjs/plugins/autoloader/prism-autoloader.js"; import "prismjs/plugins/autoloader/prism-autoloader.js";
import { defaultStore } from "@/store"; import { defaultStore } from "@/store";
// TODO Prism.plugins.autoloader.languages_path = defaultStore.state.useEmojiCdn
Prism.plugins.autoloader.languages_path = ? "https://cdn.jsdelivr.net/npm/prismjs@1.29.0/components/"
"https://cdn.jsdelivr.net/npm/prismjs@1.29.0/components/"; : "/client-assets/prismjs/components/";
const nonExistingLanguagesCache = new Set<string>(); const nonExistingLanguagesCache = new Set<string>();
export const loadLanguage = (lang: string) => export const loadLanguage = (lang: string) =>
new Promise<void>((resolve, reject) => { new Promise<void>((resolve, reject) => {
// for now
if (!defaultStore.state.useEmojiCdn) return reject();
// cached non-existing language // cached non-existing language
if (nonExistingLanguagesCache.has(lang)) return reject(); if (nonExistingLanguagesCache.has(lang)) return reject();
// load language with autoloader // load language with autoloader