made the blog category a search string
All checks were successful
Web/pipeline/head This commit looks good

This commit is contained in:
Ell 2021-03-31 17:00:15 +02:00
parent 8e2dc6f2f4
commit 7470a20886
3 changed files with 10 additions and 4 deletions

View file

@ -237,7 +237,6 @@
<ul>
<li>A cookie named <code>dark</code> with the value <code>true</code> or <code>false</code> that stores if you have dark mode enabled</li>
<li>A cookie named <code>notification</code> with the value <code>true</code> or <code>false</code> that stores if you have already closed the cookie notification that displays at the top of the page</li>
<li>A cookie named <code>category</code> that stores the category in the blog that you last selected</li>
</ul>
<p>Due to widgets and embeds, additional information will be stored by other sites. Please refer to those sites' privacy policies for more information:</p>
<ul>

View file

@ -41,7 +41,7 @@ fs.readFile(`${folder}index.html`, function (_, html) {
document.querySelector('meta[property="og:description"]').setAttribute("content", post.summary);
document.getElementById("nav-items").innerHTML = /*html*/ `
<a class="nav-item nav-link" href="../#blog">Back to Main Page</a>
<a class="nav-item nav-link" href="../?cat=${post.cat[0]}#blog">Back to Main Page</a>
${last ? /*html*/ `<a class="nav-item nav-link" href="./${last.id}">Previous ${post.cat[0]} Post</a>` : ""}
${next ? /*html*/ `<a class="nav-item nav-link" href="./${next.id}">Next ${post.cat[0]} Post</a>` : ""}
`;

View file

@ -9,7 +9,14 @@ $.ajax({
url: "blog/src/posts.json",
cache: false,
success: function (json) {
populateBlog(json, getCookie("category") || "Featured");
let category = "Featured";
let match = window.location.search.match(/cat=([^&]+)/);
if (match) {
let cat = decodeURI(match[1]);
if (json.some(p => p.cat.includes(cat)))
category = cat;
}
populateBlog(json, category);
forceToAnchor();
}
});
@ -59,7 +66,7 @@ function addCatButton(json, cats, cat, currCat) {
cats.append( /*html*/ `<button type="button" class="btn btn-link blog-cat-button" id=${catAnchor} ${cat === currCat ? "disabled" : ""}>${cat}</button>`);
$(`#${catAnchor}`).on('click', function () {
populateBlog(json, cat);
setCookie("category", cat, 365);
history.replaceState(null, null, `?cat=${cat}${location.hash}`);
});
}
}