Skip to content

Commit

Permalink
Add backlinks to footnotes on page
Browse files Browse the repository at this point in the history
* Added JavaScript written by @NieDzejkob from Zola issue
  getzola/zola/issues/1285
* Changed styling for footnotes
* Updated index template to include site.js
  • Loading branch information
wjwat committed Mar 26, 2022
1 parent 7bc18bf commit f3371bb
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
36 changes: 35 additions & 1 deletion sass/_base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ a {
color: $link-color;
text-decoration: none;
cursor: pointer;
border-bottom: 1px solid $link-color;
// border-bottom: 1px solid $link-color;

&:visited {
color: $link-color;
Expand Down Expand Up @@ -62,3 +62,37 @@ blockquote {
font-style: italic;
font-weight: bold;
}

.footnote-definition {
border-left: 2px solid $header-footer-bg;
margin-bottom: 1rem;
padding-right: 10px;

sup {
font-weight: bold;
padding-left: 5px;
}

p {
margin: 0 1rem;
font-size: 0.9rem;
}
}

.footnote-reference {
font-weight: bold;
margin-left: 1px;

// &:before { content: "[" }
// &:after { content: "]" }
}

.contributor-info {
p {
margin: 0;

&:before {
content: "";
}
}
}
23 changes: 23 additions & 0 deletions static/site.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// This adds links back to where a footnote is originally referenced.
const addBackLinks = () => {
for (const ref of document.getElementsByClassName('footnote-reference')) {
const hash = ref.children[0].hash.substring(1);
const refhash = 'ref:' + hash;
ref.id = refhash;
}

for (const footnote of document.getElementsByClassName('footnote-definition')) {
const hash = footnote.id;
const refhash = 'ref:' + hash;
const backlink = document.createElement('a');

backlink.href = '#' + refhash;
backlink.className = 'footnote-backlink';
backlink.innerText = '^';

sup = footnote.children[0];
sup.appendChild(backlink);
}
}

window.addEventListener('load', addBackLinks);
1 change: 1 addition & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,6 @@
<script type="text/javascript" src="{{ get_url(path="elasticlunr.min.js") }}"></script>
<script type="text/javascript" src="{{ get_url(path="search_index.en.js") }}"></script>
<script type="text/javascript" src="{{ get_url(path="search.js") }}"></script>
<script type="text/javascript" src="{{ get_url(path="site.js") }}"></script>
</body>
</html>

0 comments on commit f3371bb

Please sign in to comment.