diff options
| -rw-r--r-- | app/constants.mjs | 1 | ||||
| -rw-r--r-- | app/directory.mjs | 8 | ||||
| -rw-r--r-- | app/index.mjs | 2 | ||||
| -rw-r--r-- | app/static/css/globalstyles.css | 9 | ||||
| -rw-r--r-- | app/static/scripts/rebuild.js | 14 | ||||
| -rw-r--r-- | app/views/error.ejs | 9 | ||||
| -rw-r--r-- | app/views/index.ejs | 7 | ||||
| -rw-r--r-- | app/views/page.ejs | 11 | ||||
| -rw-r--r-- | app/views/partials/header.ejs | 5 | ||||
| -rw-r--r-- | app/views/partials/navbar.ejs | 3 | ||||
| -rw-r--r-- | app/views/purge.ejs | 15 | ||||
| -rw-r--r-- | app/views/rebuild.ejs | 14 |
12 files changed, 70 insertions, 28 deletions
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('<div class=\'box\'>Successfully rebuilt page directory.</div>'); + }, + error: () => { + $('#response').html('<div class=\'box\'>Could not rebuild page directory. Try again later.</div>'); + } + }); + }); +}); 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 @@ <body> <div id="main-container"> <%- include('partials/header') %> - <div id="content"> - <h1>An error occurred (<%= code %>)</h1> - <p>Go <a href="/">home</a>?</p> + <div id="content-container"> + <%- include('partials/navbar') %> + <div id="content"> + <h1>An error occurred (<%= code %>)</h1> + <p>Go <a href="/">home</a>?</p> + </div> </div> </div> </body> 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 @@ <body> <div id="main-container"> <%- include('partials/header') %> - <div id="content"> - <%- page %> + <div id="content-container"> + <%- include('partials/navbar') %> + <div id="content"> + <%- page %> + </div> </div> </div> </body> 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 @@ <body> <div id="main-container"> <%- include('partials/header') %> - <div id="content"> - <%- content %> - <hr> - <span class=footer><a href="https://github.com/LMBishop/website">GitHub</a> | <a href="/<%= path %>.wiki">View raw</a> | Page built: <%= buildTime %> | <a href="/special/purge/<%= path %>">Purge this page</a></span> + <div id="content-container"> + <%- include('partials/navbar') %> + <div id="content"> + <%- content %> + <hr> + <span class=footer><a href="https://github.com/LMBishop/website">GitHub</a> | <a href="/<%= path %>.wiki">View raw</a> | Page built: <%= buildTime %> | <a href="/special/purge/<%= path %>">Purge this page</a></span> + </div> </div> </div> </body> 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 @@ ███████ ███████ ██████ ██ ████ ██ ██ ██ ██ ██████ ██████ ██████ ██ ███████ ██ ██ ██████ ██ -</pre> -<div id="navbar"> - <%- navbar %> -</div>
\ No newline at end of file +</pre>
\ 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 @@ +<div id="navbar"> + <%- navbar %> +</div>
\ 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 @@ <body> <div id="main-container"> <%- include('partials/header') %> - <div id="content"> - <h1>Purge page</h1> - <span id="response"></span> - <p>Are you sure you wish to purge the page <span class="highlight"><%= page %></span>?</p> - <p>The last build time for this page was <span class="highlight"><%= buildTime %></span> (<span class="highlight"><%= buildTimeRelative %></span> minutes ago).</p> - <button id="confirm" data-page="<%= page %>">Confirm</button> + <div id="content-container"> + <%- include('partials/navbar') %> + <div id="content"> + <h1>Purge page</h1> + <span id="response"></span> + <p>Are you sure you wish to purge the page <span class="highlight"><%= page %></span>?</p> + <p>The last build time for this page was <span class="highlight"><%= buildTime %></span> (<span class="highlight"><%= buildTimeRelative %></span> minutes ago).</p> + <button id="confirm" data-page="<%= page %>">Confirm</button> + </div> </div> </div> </body> 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 @@ <head> <title>Rebuild</title> <link rel="stylesheet" href="/css/globalstyles.css"> + <script src="https://code.jquery.com/jquery-3.6.0.min.js" ntegrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script> + <script src="/scripts/rebuild.js"></script> </head> <body> <div id="main-container"> <%- include('partials/header') %> - <div id="content"> - <h1>Rebuild</h1> - <p>Are you sure you wish to rebuild the page directory?</p> - <button>Confirm</button> + <div id="content-container"> + <%- include('partials/navbar') %> + <div id="content"> + <h1>Rebuild</h1> + <span id="response"></span> + <p>Are you sure you wish to rebuild the page directory?</p> + <button id="confirm">Confirm</button> + </div> </div> </div> </body> |
