mirror of
https://github.com/RGBCube/Site
synced 2025-08-01 13:37:49 +00:00
headers: make them actually have unique IDs
This commit is contained in:
parent
e799cc1c45
commit
c96c59ecf5
1 changed files with 1 additions and 5 deletions
6
site.ts
6
site.ts
|
@ -70,8 +70,6 @@ site.process([".html"], (pages) => {
|
||||||
wrapper.appendChild(element);
|
wrapper.appendChild(element);
|
||||||
});
|
});
|
||||||
|
|
||||||
const encountered: Record<string, boolean> = {};
|
|
||||||
|
|
||||||
document
|
document
|
||||||
.querySelectorAll(".text-content :where(h1, h2, h3, h4, h5, h6)")
|
.querySelectorAll(".text-content :where(h1, h2, h3, h4, h5, h6)")
|
||||||
.forEach((header) => {
|
.forEach((header) => {
|
||||||
|
@ -90,13 +88,11 @@ site.process([".html"], (pages) => {
|
||||||
let textUnique = textNormalized;
|
let textUnique = textNormalized;
|
||||||
let counter = 1;
|
let counter = 1;
|
||||||
|
|
||||||
while (encountered[textUnique]) {
|
while (document.getElementById(textUnique)) {
|
||||||
counter++;
|
counter++;
|
||||||
textUnique = `${textNormalized}-${counter}`;
|
textUnique = `${textNormalized}-${counter}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
encountered[textUnique] = true;
|
|
||||||
|
|
||||||
header.id = textUnique;
|
header.id = textUnique;
|
||||||
|
|
||||||
const link = document.createElement("a");
|
const link = document.createElement("a");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue