Skip to content

Commit

Permalink
feat(docs): add header anchor links
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabian Wiles authored and alexeagle committed Feb 12, 2020
1 parent 4dde728 commit 2002046
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions docs/_includes/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,26 @@
form.submit();
};

function setAnchors() {
const headerSelectors = ['h1', 'h2', 'h3'];

headerSelectors.forEach(selector => {
const headers = document.querySelectorAll(selector)
headers.forEach(header => {
anchor = document.createElement('a');
// headers id's are already set by jykell
const id = header.getAttribute('id');
if(id) {
anchor.href = '#' + id;
anchor.innerText = '# '
header.prepend(anchor);
}
});

})

}

$(document).ready(function() {
// Scroll to anchor of location hash, adjusted for fixed navbar.
window.setTimeout(function() {
Expand All @@ -71,6 +91,9 @@
// Highlight the current item on the sidebar.
highlightCurrentSidebarNav();

// setup anchors
setAnchors();

// Handler to capture the ENTER keypress for the CSE search input
// in the page header and then call submitSearch() to submit the search
// query.
Expand Down

0 comments on commit 2002046

Please sign in to comment.