add previous post and next post buttons to blog pages

This commit is contained in:
Ellpeck 2019-10-09 23:22:47 +02:00
parent e29744e532
commit 22b93e71d8
1 changed files with 10 additions and 2 deletions

View File

@ -26,7 +26,8 @@ module.exports = function () {
fs.readFile(folder + "blog/posts.json", function (_, data) {
let json = JSON.parse(data);
for (let post of json) {
for (let i = 0; i < json.length; i++) {
let post = json[i];
let id = post["id"];
fs.readFile(folder + "blog/" + id + ".md", function (_, content) {
let dom = new JSDOM(template);
@ -36,7 +37,14 @@ module.exports = function () {
document.querySelector('meta[property="og:title"]').setAttribute("content", post["name"]);
document.querySelector('meta[name="description"]').setAttribute("content", post["summary"]);
document.querySelector('meta[property="og:description"]').setAttribute("content", post["summary"]);
document.getElementById("nav-items").innerHTML = '<a class="nav-item nav-link" href="/#blog-' + id + '">Back to Main Page</a>'
var nav = "";
nav += '<a class="nav-item nav-link" href="/#blog-' + id + '">Back to Main Page</a>';
if (i > 0)
nav += '<a class="nav-item nav-link" href="/blog-' + json[i - 1]["id"] + '">Previous Post</a>';
if (i < json.length - 1)
nav += '<a class="nav-item nav-link" href="/blog-' + json[i + 1]["id"] + '">Next Post</a>';
document.getElementById("nav-items").innerHTML = nav;
var c = "";
c += '<div class="list-display rounded">';