made the blog navigation be loaded dynamically
This commit is contained in:
parent
73c3520490
commit
08244caa2f
2 changed files with 21 additions and 4 deletions
|
@ -49,10 +49,7 @@ function createBlogPages(folder) {
|
||||||
|
|
||||||
var nav = "";
|
var nav = "";
|
||||||
nav += '<a class="nav-item nav-link" href="/#blog">Back to Main Page</a>';
|
nav += '<a class="nav-item nav-link" href="/#blog">Back to Main Page</a>';
|
||||||
if (i > 0)
|
nav += '<script src="scripts/blog-nav.js"></script>';
|
||||||
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;
|
document.getElementById("nav-items").innerHTML = nav;
|
||||||
|
|
||||||
var c = "";
|
var c = "";
|
||||||
|
|
20
scripts/blog-nav.js
Normal file
20
scripts/blog-nav.js
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
$.ajax({
|
||||||
|
dataType: "json",
|
||||||
|
url: "blog/posts.json",
|
||||||
|
cache: false,
|
||||||
|
success: function (json) {
|
||||||
|
for (let i = json.length - 1; i >= 0; i--) {
|
||||||
|
let post = json[i];
|
||||||
|
if (!$("#blog-post-" + post["id"]).length)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
let nav = "";
|
||||||
|
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>';
|
||||||
|
$("#nav-items").append(nav);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
Loading…
Reference in a new issue