Fix buildThemeList() function to ensure no duplicates (#1466)

Co-authored-by: Dessalines <dessalines@users.noreply.github.com>
This commit is contained in:
Scott 2023-06-22 22:25:11 +09:30 committed by GitHub
parent 902930bb9d
commit 0247f8a2cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4,15 +4,20 @@ import { readdir } from "fs/promises";
const extraThemesFolder = const extraThemesFolder =
process.env["LEMMY_UI_EXTRA_THEMES_FOLDER"] || "./extra_themes"; process.env["LEMMY_UI_EXTRA_THEMES_FOLDER"] || "./extra_themes";
const themes = ["darkly", "darkly-red", "litely", "litely-red"]; const themes: ReadonlyArray<string> = [
"darkly",
"darkly-red",
"litely",
"litely-red",
];
export async function buildThemeList(): Promise<string[]> { export async function buildThemeList(): Promise<ReadonlyArray<string>> {
if (existsSync(extraThemesFolder)) { if (existsSync(extraThemesFolder)) {
const dirThemes = await readdir(extraThemesFolder); const dirThemes = await readdir(extraThemesFolder);
const cssThemes = dirThemes const cssThemes = dirThemes
.filter(d => d.endsWith(".css")) .filter(d => d.endsWith(".css"))
.map(d => d.replace(".css", "")); .map(d => d.replace(".css", ""));
themes.push(...cssThemes); return themes.concat(cssThemes);
} }
return themes; return themes;
} }