20 lines
777 B
TypeScript
20 lines
777 B
TypeScript
import { parseSettingsSource, SettingsEntry } from './settingsIndex';
|
|||
|
|
|
||
|
|
// [Gitea #463] The settings source, as text, in its own lazily loaded chunk:
|
||
|
|
// fetched the first time someone searches, never at startup.
|
||
|
|
const sources = import.meta.glob(['../**/*.tsx', '!../**/*.test.tsx'], {
|
||
|
|
query: '?raw',
|
||
|
|
import: 'default',
|
||
|
|
}) as Record<string, () => Promise<string>>;
|
||
|
|
|
||
|
|
let index: Promise<SettingsEntry[]> | undefined;
|
||
|
|
|
||
|
|
export const loadSettingsIndex = (): Promise<SettingsEntry[]> => {
|
||
|
|
index ??= Promise.all(
|
||
|
|
Object.entries(sources).map(async ([path, load]) =>
|
||
|
|
// '../general/General.tsx' -> '/general/General.tsx' (what the parser matches)
|
||
|
|
parseSettingsSource(path.replace(/^\.\./, ''), await load()),
|
||
|
|
),
|
||
|
|
).then((all) => all.flat());
|
||
|
|
return index;
|
||
|
|
};
|