filter theme file

This commit is contained in:
pompurin404 2024-09-21 15:43:14 +08:00
parent e92b3d250a
commit ca42519e85
No known key found for this signature in database

View File

@ -12,14 +12,16 @@ let insertedCSSKey: string | undefined = undefined
export async function resolveThemes(): Promise<{ key: string; label: string }[]> { export async function resolveThemes(): Promise<{ key: string; label: string }[]> {
const files = await readdir(themesDir()) const files = await readdir(themesDir())
const themes = await Promise.all( const themes = await Promise.all(
files.map(async (file) => { files
const css = (await readFile(path.join(themesDir(), file), 'utf-8')) || '' .filter((file) => file.endsWith('.css'))
let name = file .map(async (file) => {
if (css.startsWith('/*')) { const css = (await readFile(path.join(themesDir(), file), 'utf-8')) || ''
name = css.split('\n')[0].replace('/*', '').replace('*/', '').trim() || file let name = file
} if (css.startsWith('/*')) {
return { key: file, label: name } name = css.split('\n')[0].replace('/*', '').replace('*/', '').trim() || file
}) }
return { key: file, label: name }
})
) )
if (themes.find((theme) => theme.key === 'default.css')) { if (themes.find((theme) => theme.key === 'default.css')) {
return themes return themes