From 031900c8c2d0d2edc3bb8811f2e79f4e8938b7de Mon Sep 17 00:00:00 2001 From: RGBCube Date: Thu, 5 Jun 2025 04:23:04 +0300 Subject: [PATCH] site: footers --- site.ts | 56 ++++++++++++++++++++++++++++++++++++- site/_includes/text.vto | 2 ++ site/assets/css/default.css | 16 +++++++++-- site/blog.vto | 2 +- site/blog/test.md | 2 +- 5 files changed, 73 insertions(+), 5 deletions(-) diff --git a/site.ts b/site.ts index 7694c6f..66a926f 100644 --- a/site.ts +++ b/site.ts @@ -89,7 +89,7 @@ site.process([".html"], (pages) => { let counter = 1; while (document.getElementById(textUnique)) { - counter++; + counter += 1; textUnique = `${textNormalized}-${counter}`; } @@ -101,6 +101,60 @@ site.process([".html"], (pages) => { header.parentNode!.insertBefore(link, header); link.appendChild(header); }); + + const footnotes = document.querySelector("#footnotes"); + if (footnotes) { + let counter = 0; + + document.querySelectorAll("p").forEach((paragraph) => { + const matches = paragraph.innerHTML.match(/\[\^([^\]]*)\]/g); + if (!matches) return; + + let newHTML = paragraph.innerHTML; + + matches.forEach((match) => { + const footnoteText = match.slice(2, -1); + + let number; + let addFooter; + + if (footnoteText.match(/^[1-9]+$/g)) { + number = parseInt(footnoteText); + addFooter = false; + } else { + counter += 1; + number = counter; + addFooter = true; + } + + const anchorId = `ref:${counter}`; + const footnoteId = `fn:${counter}`; + + const link = + `^${number}`; + newHTML = newHTML.replace(match, link); + + if (addFooter) { + const hr = document.createElement("hr"); + hr.classList.add("my-1.5"); + + const li = document.createElement("li"); + li.id = footnoteId; + li.innerHTML = + `${footnoteText}..?`; + + footnotes.appendChild(hr); + footnotes.appendChild(li); + } + }); + + paragraph.innerHTML = newHTML; + }); + + if (counter === 0) { + footnotes.remove(); + } + } }); }); diff --git a/site/_includes/text.vto b/site/_includes/text.vto index a88008d..3046b9c 100644 --- a/site/_includes/text.vto +++ b/site/_includes/text.vto @@ -31,6 +31,8 @@ layout: default.vto {{> const padding = 4 }}
{{ content }} + +