From a84425a42e9246243dffd23dba33b4d4a5b626ac Mon Sep 17 00:00:00 2001 From: LMBishop <13875753+LMBishop@users.noreply.github.com> Date: Mon, 22 Nov 2021 14:17:44 +0000 Subject: Update styles & add page rebuilding --- app/constants.mjs | 1 + app/directory.mjs | 8 ++++++-- app/index.mjs | 2 +- app/static/css/globalstyles.css | 9 +++++++-- app/static/scripts/rebuild.js | 14 ++++++++++++++ app/views/error.ejs | 9 ++++++--- app/views/index.ejs | 7 +++++-- app/views/page.ejs | 11 +++++++---- app/views/partials/header.ejs | 5 +---- app/views/partials/navbar.ejs | 3 +++ app/views/purge.ejs | 15 +++++++++------ app/views/rebuild.ejs | 14 ++++++++++---- 12 files changed, 70 insertions(+), 28 deletions(-) create mode 100644 app/static/scripts/rebuild.js create mode 100644 app/views/partials/navbar.ejs diff --git a/app/constants.mjs b/app/constants.mjs index e9b4730..ace7e2f 100644 --- a/app/constants.mjs +++ b/app/constants.mjs @@ -3,6 +3,7 @@ export const SERVER_PORT = 3000; export const PARSER_MAX_RECURSION = 20; export const PURGE_COOLDOWN_MIN = -1; +export const REBUILD_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 38b05ca..b470bc7 100644 --- a/app/directory.mjs +++ b/app/directory.mjs @@ -1,6 +1,6 @@ 'use strict'; -import { PAGES_DIR, PURGE_COOLDOWN_MIN } from './constants.mjs'; +import { PAGES_DIR, PURGE_COOLDOWN_MIN, REBUILD_COOLDOWN_MIN } from './constants.mjs'; import { parse } from './wikiparser.mjs'; import { readFileSync, readdirSync } from 'fs'; @@ -22,7 +22,7 @@ export function pageFor(path) { return page; } -export function buildPage(path) { +function buildPage(path) { let data; try { data = readFileSync(`${PAGES_DIR}/${path}.wiki`, 'utf-8'); @@ -47,6 +47,9 @@ export function buildPage(path) { } export function rebuild() { + if (metadata.fileTreeBuildTime + REBUILD_COOLDOWN_MIN * 60 * 1000 > Date.now()) { + return false; + } for (var page in pages) { delete pages[page]; } @@ -70,6 +73,7 @@ export function rebuild() { }); metadata.navbar = primaryPages; metadata.fileTreeBuildTime = new Date(); + return true; } export function exists(path) { diff --git a/app/index.mjs b/app/index.mjs index cf47100..0f14ccf 100644 --- a/app/index.mjs +++ b/app/index.mjs @@ -88,7 +88,7 @@ app.get('/special/rebuild', (req, res) => { }); app.get('/special/rebuild/confirm', (req, res) => { - if (directory.rebuild()[0]) { + if (directory.rebuild()) { res.status(200).send(); } else { res.status(429).send(); diff --git a/app/static/css/globalstyles.css b/app/static/css/globalstyles.css index bdecaa6..599c836 100644 --- a/app/static/css/globalstyles.css +++ b/app/static/css/globalstyles.css @@ -5,12 +5,13 @@ font-weight: 700; line-height: 1.2; color: #ddd; + text-shadow: 0px 1px 10px #9876aa; } html, body { border: 0; margin: 0; - background-color: #000; + background-color: #111; color: #ddd; font-family: 'Cousine', monospace, sans-serif; line-height: 1.3; @@ -65,6 +66,10 @@ h1, h2, h3, h4, h5, h6 { margin: 0 auto; } +#content-container { + box-shadow: 0px 0px 15px 10px rgba(152,118,170,0.05); +} + #content { padding: 20px; max-width: 1200px; @@ -73,7 +78,7 @@ h1, h2, h3, h4, h5, h6 { } a { - color: #ffc66d; + color: #9876aa; text-decoration: underline; } diff --git a/app/static/scripts/rebuild.js b/app/static/scripts/rebuild.js new file mode 100644 index 0000000..8fd0e2e --- /dev/null +++ b/app/static/scripts/rebuild.js @@ -0,0 +1,14 @@ +$(() => { + $('#confirm').click(() => { + $.ajax({ + type: 'GET', + url: `/special/rebuild/confirm`, + success: () => { + $('#response').html('
Successfully rebuilt page directory.
'); + }, + error: () => { + $('#response').html('
Could not rebuild page directory. Try again later.
'); + } + }); + }); +}); diff --git a/app/views/error.ejs b/app/views/error.ejs index 87296bc..88e1a27 100644 --- a/app/views/error.ejs +++ b/app/views/error.ejs @@ -7,9 +7,12 @@
<%- include('partials/header') %> -
-

An error occurred (<%= code %>)

-

Go home?

+
+ <%- include('partials/navbar') %> +
+

An error occurred (<%= code %>)

+

Go home?

+
diff --git a/app/views/index.ejs b/app/views/index.ejs index ae21964..ca674f0 100644 --- a/app/views/index.ejs +++ b/app/views/index.ejs @@ -7,8 +7,11 @@
<%- include('partials/header') %> -
- <%- page %> +
+ <%- include('partials/navbar') %> +
+ <%- page %> +
diff --git a/app/views/page.ejs b/app/views/page.ejs index bca4828..4422157 100644 --- a/app/views/page.ejs +++ b/app/views/page.ejs @@ -7,10 +7,13 @@
<%- include('partials/header') %> -
- <%- content %> -
- GitHub | View raw | Page built: <%= buildTime %> | Purge this page +
+ <%- include('partials/navbar') %> +
+ <%- content %> +
+ GitHub | View raw | Page built: <%= buildTime %> | Purge this page +
diff --git a/app/views/partials/header.ejs b/app/views/partials/header.ejs index 67a23d4..6582e36 100644 --- a/app/views/partials/header.ejs +++ b/app/views/partials/header.ejs @@ -8,7 +8,4 @@ ███████ ███████ ██████ ██ ████ ██ ██ ██ ██ ██████ ██████ ██████ ██ ███████ ██ ██ ██████ ██ - - \ No newline at end of file + \ No newline at end of file diff --git a/app/views/partials/navbar.ejs b/app/views/partials/navbar.ejs new file mode 100644 index 0000000..2664d48 --- /dev/null +++ b/app/views/partials/navbar.ejs @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/app/views/purge.ejs b/app/views/purge.ejs index f36e482..54fc49b 100644 --- a/app/views/purge.ejs +++ b/app/views/purge.ejs @@ -9,12 +9,15 @@
<%- include('partials/header') %> -
-

Purge page

- -

Are you sure you wish to purge the page <%= page %>?

-

The last build time for this page was <%= buildTime %> (<%= buildTimeRelative %> minutes ago).

- +
+ <%- include('partials/navbar') %> +
+

Purge page

+ +

Are you sure you wish to purge the page <%= page %>?

+

The last build time for this page was <%= buildTime %> (<%= buildTimeRelative %> minutes ago).

+ +
diff --git a/app/views/rebuild.ejs b/app/views/rebuild.ejs index e2943f1..62076cf 100644 --- a/app/views/rebuild.ejs +++ b/app/views/rebuild.ejs @@ -3,14 +3,20 @@ Rebuild + +
<%- include('partials/header') %> -
-

Rebuild

-

Are you sure you wish to rebuild the page directory?

- +
+ <%- include('partials/navbar') %> +
+

Rebuild

+ +

Are you sure you wish to rebuild the page directory?

+ +
-- cgit v1.2.3-70-g09d2