component/static: Seperate out static file handling

This commit is contained in:
Tom Wiesing 2022-10-06 15:41:46 +02:00
parent 3d4db1744b
commit 88a2ba4297
No known key found for this signature in database
9 changed files with 43 additions and 28 deletions

View file

@ -1,19 +0,0 @@
/** Adapted from http://blog.parkermoore.de/2014/08/01/header-anchor-links-in-vanilla-javascript-for-github-pages-and-jekyll/ */
const anchorForId = (id) => {
const anchor = document.createElement("a")
anchor.className = "header-link"
anchor.href = "#" + id
anchor.innerHTML = "#"
return anchor
}
const linkifyAnchors = (level) => {
const headers = document.getElementsByTagName("h" + level);
Array.from(headers).forEach((header) => {
if (typeof header.id === "undefined" || header.id === "") return
header.appendChild(anchorForId(header.id))
})
}
// linkify all the anchors from 1 ... 6
Array(6).forEach((_, i) => linkifyAnchors(i + 1))