From 7b352281133fd50cce8ce905dc0d7e50af505af8 Mon Sep 17 00:00:00 2001 From: jrtechs Date: Sun, 31 May 2020 11:46:49 -0400 Subject: [PATCH] implemented page titles --- blog/category.js | 2 +- blog/renderBlogPost.js | 15 +++--- templates/blog/blogMain.html | 2 +- templates/blog/header.html | 93 ++++++++++++++++++++++++++++++++++++ utils/pageBuilder.js | 6 ++- 5 files changed, 109 insertions(+), 9 deletions(-) create mode 100644 templates/blog/header.html diff --git a/blog/category.js b/blog/category.js index 80fe24d..8a2e5ab 100644 --- a/blog/category.js +++ b/blog/category.js @@ -22,7 +22,7 @@ module.exports= var page = request.query.page; const category = requestURL.split("/").join(""); - + templateContext["title"] = category; sql.getPostsFromCategory(category).then(function(posts) { Promise.all([blogBodyRenderer.renderBatchOfPosts(requestURL, posts, page, 5, templateContext), diff --git a/blog/renderBlogPost.js b/blog/renderBlogPost.js index 420d81f..46e90a6 100644 --- a/blog/renderBlogPost.js +++ b/blog/renderBlogPost.js @@ -178,7 +178,6 @@ module.exports= }, - pandocWrapper: function(markdownContents, pandocArgs) { return new Promise((resolve, reject)=> @@ -208,7 +207,7 @@ module.exports= /** - * Renders a bunch of blog post previews to the user + * Renders a bunch of blog post previews to the user * * @param baseURL-- url of the page * @param posts -- sql data about the blog to render @@ -236,12 +235,12 @@ module.exports= { promises.push(new Promise(function(res, rej) { - if(posts.length != 1) - { - templateContext.preview = true - } module.exports.generateBlogPost(posts[i], posts.length === 1 ? -1: 3).then(function(tempContext) { + if(posts.length != 1) + { + templateContext.preview = true + } res(tempContext); }).catch(function(error) { @@ -254,6 +253,10 @@ module.exports= Promise.all(promises).then(function(posts) { templateContext.posts = posts; + if(posts.length == 1) + templateContext.title = posts[0].name; + else if(currentPage != 1 && baseURL === "/") + templateContext.title = "page " + currentPage; resolve(); }).catch(function(error) { diff --git a/templates/blog/blogMain.html b/templates/blog/blogMain.html index d5a4345..8657082 100644 --- a/templates/blog/blogMain.html +++ b/templates/blog/blogMain.html @@ -1,4 +1,4 @@ -{header} +{>header}




diff --git a/templates/blog/header.html b/templates/blog/header.html new file mode 100644 index 0000000..04caf1e --- /dev/null +++ b/templates/blog/header.html @@ -0,0 +1,93 @@ + + + + + + {if title} + Jrtechs: {title} + {else} + Jrtechs + {/if} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/utils/pageBuilder.js b/utils/pageBuilder.js index d4900a6..820b0d5 100644 --- a/utils/pageBuilder.js +++ b/utils/pageBuilder.js @@ -12,11 +12,15 @@ const url = require('url'); const TEMPLATE_FILE="blog/blogMain.html"; +const HEADER_TEMPLATE_FILE="blog/header.html"; +const HEADER_TEMPLATE_KEY="header"; + const PAGINATION_TEMPLATE_KEY = "paginationTemplate"; const PAGINATION_TEMPLATE_FILE = "blog/paginationBar.html"; + module.exports = { /** @@ -143,7 +147,7 @@ module.exports = var templateContext = Object(); Promise.all([includes.fetchTemplate(TEMPLATE_FILE), includes.includeInObject(PAGINATION_TEMPLATE_KEY, templateContext, "templates/" + PAGINATION_TEMPLATE_FILE), - includes.printHeader(templateContext), + includes.includeInObject(HEADER_TEMPLATE_KEY, templateContext, "templates/" + HEADER_TEMPLATE_FILE), includes.printFooter(templateContext), templateFiller(filename, request, templateContext), require("../blog/sidebar.js").main(templateContext)])