Make index page configurable

This commit is contained in:
Zef Hemel
2022-08-02 12:43:39 +02:00
parent b29b175b40
commit 7111fb6b1e
10 changed files with 81 additions and 25 deletions
+2 -1
View File
@@ -18,6 +18,7 @@
"@codemirror/view": "^6.0.0",
"@lezer/common": "1.0.0",
"@lezer/highlight": "1.0.0",
"@lezer/markdown": "1.0.1"
"@lezer/markdown": "1.0.1",
"yaml": "^1.10.2"
}
}
+16
View File
@@ -1,3 +1,5 @@
import YAML from "yaml";
export function safeRun(fn: () => Promise<void>) {
fn().catch((e) => {
console.error(e);
@@ -19,3 +21,17 @@ export function throttle(func: () => void, limit: number) {
}
};
}
// TODO: This is naive, may be better to use a proper parser
const yamlSettingsRegex = /```yaml([^`]+)```/;
export function parseYamlSettings(settingsMarkdown: string): {
[key: string]: any;
} {
const match = yamlSettingsRegex.exec(settingsMarkdown);
if (!match) {
return {};
}
const yaml = match[1];
return YAML.parse(yaml);
}