diff --git a/controllers/errorController.js b/controllers/errorController.js index 7d53b8f..7d03291 100644 --- a/controllers/errorController.js +++ b/controllers/errorController.js @@ -27,10 +27,14 @@ const sendErrorResponse = (err, req, res, devMode = false) => { // 2. FOR WEBPAGES else res.status(err.statusCode).render('error', { - title: 'Error', - statusCode: err.statusCode, - message: err.message, - ...(devMode && { stack: err.stack }), + data: { + statusCode: err.statusCode, + message: err.message, + ...(devMode && { stack: err.stack }), + }, + meta: { + title: 'Error', + }, }); }; diff --git a/controllers/viewController.js b/controllers/viewController.js index 27d55d5..a46ce35 100644 --- a/controllers/viewController.js +++ b/controllers/viewController.js @@ -11,10 +11,19 @@ import { nonSlugRoutes } from '../utils/constants.js'; // EXPORTS //////////////////////////////////////////////////////// export const about = (req, res, next) => { - res.render('about', { title: 'About' }); + res.render('about', { + meta: { + title: 'About', + }, + }); }; + export const privacy = (req, res, next) => { - res.render('privacy', { title: 'Privacy' }); + res.render('privacy', { + meta: { + title: 'Privacy', + }, + }); }; export const answers = catchAsyncErrors(async (req, res, next) => { @@ -23,23 +32,37 @@ export const answers = catchAsyncErrors(async (req, res, next) => { if (nonSlugRoutes.includes(slug)) return next(); const answersData = await getAnswers(slug); + const title = answersData.question.text.spans.map(span => span.text).join(''); res.status(200).render('answers', { - title: answersData.question.text.spans.map(span => span.text).join(''), data: answersData, + meta: { + title, + }, }); }); export const topic = catchAsyncErrors(async (req, res, next) => { const topicData = await getTopic(req.params.slug); - res.status(200).render('topic', { title: topicData.name, data: topicData }); + res.status(200).render('topic', { + data: topicData, + meta: { + title: topicData.name, + }, + }); }); export const unimplemented = (req, res, next) => { + const message = + "This route isn't yet implemented. Check back sometime later!"; res.status(501).render('error', { - title: 'Not yet implemented', - statusCode: 501, - message: "This route isn't yet implemented. Check back sometime later!", + data: { + statusCode: 501, + message, + }, + meta: { + title: 'Not yet implemented', + }, }); }; diff --git a/views/pug/_header.pug b/views/pug/_header.pug index 02e5db5..86e4f13 100644 --- a/views/pug/_header.pug +++ b/views/pug/_header.pug @@ -1,4 +1,4 @@ -header.header(class=`${title === 'About' ? 'header__about': ''}`) +header.header(class=`${meta.title === 'About' ? 'header__about': ''}`) .header__bar a.header__link.header__logo(href='/') Quetre diff --git a/views/pug/base.pug b/views/pug/base.pug index e3e70ca..f083dd6 100644 --- a/views/pug/base.pug +++ b/views/pug/base.pug @@ -6,7 +6,8 @@ html(lang='en') meta(http-equiv='X-UA-Compatible', content='IE=edge') meta(name='viewport', content='width=device-width, initial-scale=1.0') //- appending title to name in case it exists, else showing name as the title of the page - title= title ? `${title} | Quetre`: 'Quetre' + - const pageTitle = meta.title ? `${meta.title} | Quetre`: 'Quetre' + title= pageTitle meta(name="description", content="A libre front-end for Quora. See any answer without being tracked, without being required to log in, and without being bombarded by pesky ads.") //- preloading css and fonts for performance gains link(rel='preload', href='/fonts/WorkSans.woff2', as='font', type='font/woff2', crossorigin) diff --git a/views/pug/error.pug b/views/pug/error.pug index e809b57..0bbe202 100644 --- a/views/pug/error.pug +++ b/views/pug/error.pug @@ -2,13 +2,13 @@ extends base block content main#main.main.error - p.error__code= statusCode - p.error__message= message + p.error__code= data.statusCode + p.error__message= data.message //- will only apply in dev mode - if stack + if data.stack .error__stack-box: pre.error__stack - code.error__text= stack + code.error__text= data.stack p.error__return Go back to the  a.error__link(href="/") Home Page