don't add unnecessary anchors if we force to the anchor anyway
All checks were successful
Web/pipeline/head This commit looks good

This commit is contained in:
Ell 2021-06-24 00:21:16 +02:00
parent 851c534879
commit 052ef46de5
3 changed files with 12 additions and 7 deletions

View file

@ -164,7 +164,6 @@
<!-- Blog -->
<span class="anchor" id="blog"></span>
<div id="blog-cat-anchors"></div>
<div class="list-display rounded">
<h1>Blog</h1>
<p>

View file

@ -11,7 +11,12 @@ $.ajax({
success: function (json) {
let category = window.location.hash.match(/#blog-(.+)/);
populateBlog(json, category && decodeURI(category[1]) || "featured");
forceToAnchor();
let anchor = window.location.hash;
// blog categories should also move to the blog
if (anchor.startsWith("#blog-"))
anchor = anchor.substring(0, 5);
forceToAnchor(anchor);
}
});

View file

@ -9,13 +9,14 @@ function setCookie(key, value, days) {
document.cookie = `${key}=${value}; expires=${date.toUTCString()}; path=/`;
}
function forceToAnchor() {
function forceToAnchor(customAnchor) {
let anchor = customAnchor || window.location.hash;
// this is probably a terrible hack
if (window.location.hash.startsWith("#")) {
let anchor = $(window.location.hash);
if (anchor.length) {
if (anchor.startsWith("#")) {
let element = $(anchor);
if (element.length) {
$('html, body').animate({
scrollTop: anchor.offset().top
scrollTop: element.offset().top
}, 0);
}
}