From b8eb09b46b2400c3650a7790115b396414dd56d3 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sun, 27 Oct 2024 23:12:55 +0200 Subject: [PATCH] server: Refactor code block theme search into own service --- src/routes/api/options.ts | 16 ++-------------- src/services/code_block_theme.ts | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 14 deletions(-) create mode 100644 src/services/code_block_theme.ts diff --git a/src/routes/api/options.ts b/src/routes/api/options.ts index 227d5c8af..c8f99fd77 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 dialog const 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.ts new file mode 100644 index 000000000..d06694580 --- /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