Web/scripts/blog-nav.js

20 lines
660 B
JavaScript
Raw Normal View History

$.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;
}
}
});