component/static: Seperate out static file handling
This commit is contained in:
parent
3d4db1744b
commit
88a2ba4297
9 changed files with 43 additions and 28 deletions
19
internal/component/static/out/control/autolink.js
Normal file
19
internal/component/static/out/control/autolink.js
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
/** 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))
|
||||
Loading…
Add table
Add a link
Reference in a new issue