add previous post and next post buttons to blog pages
This commit is contained in:
parent
e29744e532
commit
22b93e71d8
1 changed files with 10 additions and 2 deletions
12
node/blog.js
12
node/blog.js
|
@ -26,7 +26,8 @@ module.exports = function () {
|
||||||
|
|
||||||
fs.readFile(folder + "blog/posts.json", function (_, data) {
|
fs.readFile(folder + "blog/posts.json", function (_, data) {
|
||||||
let json = JSON.parse(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"];
|
let id = post["id"];
|
||||||
fs.readFile(folder + "blog/" + id + ".md", function (_, content) {
|
fs.readFile(folder + "blog/" + id + ".md", function (_, content) {
|
||||||
let dom = new JSDOM(template);
|
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[property="og:title"]').setAttribute("content", post["name"]);
|
||||||
document.querySelector('meta[name="description"]').setAttribute("content", post["summary"]);
|
document.querySelector('meta[name="description"]').setAttribute("content", post["summary"]);
|
||||||
document.querySelector('meta[property="og: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 = "";
|
var c = "";
|
||||||
c += '<div class="list-display rounded">';
|
c += '<div class="list-display rounded">';
|
||||||
|
|
Loading…
Reference in a new issue