A good starting point is the Hugo footnotes
But I have done some improvements (according to my needs), as the following:
- link (at the end of a html page) the file footnotes.js, with this content:
function getFootnoteContent(index) {
const id = "fn:" + index;
const fn = document.getElementById(id);
return fn.innerHTML.trim();
}
function footnotePopup(showIndex, showCloseBtn) {
const popupWrapper = document.querySelector("#popup-wrapper");
// Set whether to display index and/or close button. Default is true for both
if (showIndex === undefined) {
showIndex = true;
}
if (showCloseBtn === undefined) {
showCloseBtn = false;
}
// Create main container that will hold footnote content
const popupContent = popupWrapper.appendChild(document.createElement("div"));
popupContent.id = "popup-content";
let popupIndex = null;
if (showIndex) {
popupIndex = popupWrapper.insertBefore(
document.createElement("div"),
popupContent
);
popupIndex.id = "popup-index";
}
let popupCloseButton = null;
if (showCloseBtn) {
popupCloseButton = popupWrapper.appendChild(document.createElement("div"));
popupCloseButton.innerHTML = "[x]";
popupCloseButton.id = "popup-close";
}
// Remove redundant [return] links from footnote list (optional)
const fnReturns = document.querySelectorAll("a.footnote-return");
fnReturns.forEach(function (fnReturn) {
const parent = fnReturn.parentNode;
parent.removeChild(fnReturn);
});
const fnRefs = document.querySelectorAll("a[id^='fnref:']");
fnRefs.forEach(function (fnRef) {
fnRef.addEventListener("click", handler("refs", fnRef));
});
//window.addEventListener("scroll", handler("close"));
document.addEventListener(
"click",
function (event) {
if (
event.target.matches("a[id^='fnref']") ||
event.target.matches("#popup-content")
) {
return;
}
popupWrapper.style.display = "none";
},
false
);
if (showCloseBtn) {
popupCloseButton.addEventListener("click", handler("close"));
}
function handler(type, node) {
console.log("test");
return function (event) {
if (type === "close") {
popupWrapper.style.display = "none";
}
if (type === "refs") {
event.preventDefault();
const index = node.id.substring(6);
if (showIndex) {
popupIndex.innerHTML = index + ".";
}
popupContent.innerHTML = getFootnoteContent(index);
popupWrapper.style.display = "flex";
}
};
}
}
footnotePopup(false, true);
2) Put, before that link, the div where the note will be shown
<div class=\"bottom-panel\" id=\"bottom-panel\">
<div class=\"popup-wrapper\" id=\"popup-wrapper\"></div>
</div>
3) Modify the anchor tag (within your main text), with something like
<a href="#n1" id="fnref:1">[1]</a>
4) and the footnote should be like the following:
<p id="fn:1"><a href="#fnref:1">[1]</a> your footnote here.</p>