Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use Hugo render hooks for header link rendering #425

Merged
merged 1 commit into from
Dec 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public/

node_modules/
build/
gen_/

## OS Files
# Windows
Expand Down
10 changes: 0 additions & 10 deletions assets/js/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -544,15 +544,6 @@ function initTable () {
})
}

function initHeaderLink () {
for (let num = 1; num <= 6; num++) {
forEach(document.querySelectorAll('.single .content > h' + num), $header => {
$header.classList.add('headerLink')
$header.insertAdjacentHTML('afterbegin', `<a href="#${$header.id}" class="header-mark"></a>`)
})
}
}

function initToc () {
const tocCore = document.getElementById('TableOfContents')
// Return directly if no toc
Expand Down Expand Up @@ -856,7 +847,6 @@ function init () {
initLightGallery()
initHighlight()
initTable()
initHeaderLink()
initTypeit()
initMapbox()
initToc()
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

4 changes: 4 additions & 0 deletions layouts/_default/_markup/render-heading.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<h{{ .Level }} id="{{ .Anchor | safeURL }}" class="headerLink">
<a href="#{{ .Anchor | safeURL }}" class="header-mark"></a>
{{- .Text | safeHTML -}}
</h{{ .Level }}>