Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
server: Refactor code block theme search into own service
Elian Doranb8eb09b46b24
diff --git a/src/routes/api/options.ts b/src/routes/api/options.tsindex 227d5c8af5..c8f99fd775 100644--- a/src/routes/api/options.ts+++ b/src/routes/api/options.ts@@ -6,7 +6,7 @@ import searchService from "../../services/search/services/search.js";import ValidationError from "../../errors/validation_error.js";import { Request } from 'express';import { changeLanguage } from "../../services/i18n.js";-import fs from "fs";+import { listSyntaxHighlightingThemes } from "../../services/code_block_theme.js";// options allowed to be updated directly in the Options dialogconst ALLOWED_OPTIONS = new Set([@@ -142,19 +142,7 @@ function getUserThemes() {}function getSyntaxHighlightingThemes() {- const path = "node_modules/@highlightjs/cdn-assets/styles";- const allThemes = fs- .readdirSync(path)- .filter((el) => el.endsWith(".min.css"))- .map((name) => {- const nameWithoutExtension = name.replace(".min.css", "");-- return {- val: `default:${nameWithoutExtension}`,- title: nameWithoutExtension.replace(/-/g, " ")- };- });- return allThemes;+ return listSyntaxHighlightingThemes();}function getSupportedLocales() {diff --git a/src/services/code_block_theme.ts b/src/services/code_block_theme.tsnew file mode 100644index 0000000000..d06694580d--- /dev/null+++ b/src/services/code_block_theme.ts@@ -0,0 +1,17 @@+import fs from "fs";++export function listSyntaxHighlightingThemes() {+ const path = "node_modules/@highlightjs/cdn-assets/styles";+ const allThemes = fs+ .readdirSync(path)+ .filter((el) => el.endsWith(".min.css"))+ .map((name) => {+ const nameWithoutExtension = name.replace(".min.css", "");++ return {+ val: `default:${nameWithoutExtension}`,+ title: nameWithoutExtension.replace(/-/g, " ")+ };+ });+ return allThemes;+}\ No newline at end of file