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 | |
| parent | 6f52ba399d355c4efc477916a05b59ba46b20116 (diff) | |
Handle purging deleted pages
| -rw-r--r-- | app/constants.mjs | 2 | ||||
| -rw-r--r-- | app/directory.mjs | 14 |
2 files changed, 12 insertions, 4 deletions
diff --git a/app/constants.mjs b/app/constants.mjs index 96068e1..e9b4730 100644 --- a/app/constants.mjs +++ b/app/constants.mjs @@ -2,7 +2,7 @@ export const SERVER_PORT = 3000; export const PARSER_MAX_RECURSION = 20; -export const PURGE_COOLDOWN_MIN = 10; +export const PURGE_COOLDOWN_MIN = -1; export const PAGES_DIR = 'pages'; export const TEMPLATE_DIR = 'pages/tempates'; export const IMAGES_DIR = 'pages/images'; 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; |
