mirror of
https://github.com/pompurin404/mihomo-party.git
synced 2024-11-15 19:22:31 +08:00
filter theme file
This commit is contained in:
parent
e92b3d250a
commit
ca42519e85
|
@ -12,14 +12,16 @@ let insertedCSSKey: string | undefined = undefined
|
|||
export async function resolveThemes(): Promise<{ key: string; label: string }[]> {
|
||||
const files = await readdir(themesDir())
|
||||
const themes = await Promise.all(
|
||||
files.map(async (file) => {
|
||||
const css = (await readFile(path.join(themesDir(), file), 'utf-8')) || ''
|
||||
let name = file
|
||||
if (css.startsWith('/*')) {
|
||||
name = css.split('\n')[0].replace('/*', '').replace('*/', '').trim() || file
|
||||
}
|
||||
return { key: file, label: name }
|
||||
})
|
||||
files
|
||||
.filter((file) => file.endsWith('.css'))
|
||||
.map(async (file) => {
|
||||
const css = (await readFile(path.join(themesDir(), file), 'utf-8')) || ''
|
||||
let name = file
|
||||
if (css.startsWith('/*')) {
|
||||
name = css.split('\n')[0].replace('/*', '').replace('*/', '').trim() || file
|
||||
}
|
||||
return { key: file, label: name }
|
||||
})
|
||||
)
|
||||
if (themes.find((theme) => theme.key === 'default.css')) {
|
||||
return themes
|
||||
|
|
Loading…
Reference in New Issue
Block a user