server: Refactor code block theme search into own service

This commit is contained in:
Elian Doran 2024-10-27 23:12:55 +02:00
parent 5682b2d819
commit b8eb09b46b
No known key found for this signature in database
2 changed files with 19 additions and 14 deletions

View File

@ -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() {

View File

@ -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;
}