diff options
| author | LMBishop <13875753+LMBishop@users.noreply.github.com> | 2021-11-21 22:38:00 +0000 |
|---|---|---|
| committer | LMBishop <13875753+LMBishop@users.noreply.github.com> | 2021-11-21 22:38:00 +0000 |
| commit | b49458699376b18c3f5a018973669685e213ef62 (patch) | |
| tree | 2a80d98322619c7e8397cadb86295d3ef52c2a04 /app/directory.mjs | |
| parent | 6f52ba399d355c4efc477916a05b59ba46b20116 (diff) | |
Handle purging deleted pages
Diffstat (limited to 'app/directory.mjs')
| -rw-r--r-- | app/directory.mjs | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/app/directory.mjs b/app/directory.mjs index 1fddf23..89a6ee9 100644 --- a/app/directory.mjs +++ b/app/directory.mjs @@ -23,7 +23,12 @@ export function pageFor(path) { } export function buildPage(path) { - let data = readFileSync(`${PAGES_DIR}/${path}.wiki`, 'utf-8'); + let data; + try { + data = readFileSync(`${PAGES_DIR}/${path}.wiki`, 'utf-8'); + } catch { + return false; + } let result = parse(data); let title = result.metadata.displayTitle ?? 'Unnamed page'; let content = `<h1>${title}</h1>${result.html}`; @@ -35,6 +40,7 @@ export function buildPage(path) { displayTitle: title }; pages[path] = page; + return true; } export function rebuild() { @@ -67,8 +73,10 @@ export function purge(path) { return false; } else { pages[path] = {}; - buildPage(path); - return true; + if (buildPage(path)) { + return true; + } + delete pages[path]; } } return false; |
