mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-17 21:01:26 +02:00
Merge commit '5be51ac3db225d5df501ed1fa1499c41d97dbf65'
This commit is contained in:
@@ -1,6 +1,24 @@
|
||||
export const navbar = (Alpine) => ({
|
||||
init: function () {
|
||||
Alpine.bind(this.$root, this.root);
|
||||
|
||||
return this.$nextTick(() => {
|
||||
let contentEl = document.querySelector('.content:not(.content--ready)');
|
||||
if (contentEl) {
|
||||
contentEl.classList.add('content--ready');
|
||||
let anchorTemplate = document.getElementById('anchor-heading');
|
||||
if (anchorTemplate) {
|
||||
let els = contentEl.querySelectorAll('h2[id], h3[id], h4[id], h5[id], h6[id], dt[id]');
|
||||
for (let i = 0; i < els.length; i++) {
|
||||
let el = els[i];
|
||||
el.classList.add('group');
|
||||
let a = anchorTemplate.content.cloneNode(true).firstElementChild;
|
||||
a.href = '#' + el.id;
|
||||
el.appendChild(a);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
root: {
|
||||
['@scroll.window.debounce.10ms'](event) {
|
||||
|
Reference in New Issue
Block a user