mirror of
https://github.com/thiloho/archtika.git
synced 2025-11-22 10:51:36 +01:00
Generate nested table of contents
This commit is contained in:
@@ -164,9 +164,6 @@ in
|
|||||||
alias = "/var/www/archtika-websites/previews/";
|
alias = "/var/www/archtika-websites/previews/";
|
||||||
index = "index.html";
|
index = "index.html";
|
||||||
tryFiles = "$uri $uri/ $uri/index.html =404";
|
tryFiles = "$uri $uri/ $uri/index.html =404";
|
||||||
extraConfig = ''
|
|
||||||
autoindex on;
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
"/api/" = {
|
"/api/" = {
|
||||||
proxyPass = "http://localhost:${toString cfg.port}/";
|
proxyPass = "http://localhost:${toString cfg.port}/";
|
||||||
|
|||||||
@@ -94,20 +94,41 @@ const createMarkdownParser = (showToc = true) => {
|
|||||||
postprocess(html: string) {
|
postprocess(html: string) {
|
||||||
const closingRemainingSection = "</section>".repeat(sectionStack.length);
|
const closingRemainingSection = "</section>".repeat(sectionStack.length);
|
||||||
|
|
||||||
const tableOfContents =
|
let tableOfContents = "";
|
||||||
showToc && headings.length > 0
|
if (showToc && headings.length > 0) {
|
||||||
? `<details class="table-of-contents">
|
const tocItems = [];
|
||||||
|
let currentLevel = 0;
|
||||||
|
|
||||||
|
for (const { id, text, level } of headings) {
|
||||||
|
while (currentLevel < level - 1) {
|
||||||
|
tocItems.push("<ul>");
|
||||||
|
currentLevel++;
|
||||||
|
}
|
||||||
|
while (currentLevel > level - 1) {
|
||||||
|
tocItems.push("</ul>");
|
||||||
|
currentLevel--;
|
||||||
|
}
|
||||||
|
tocItems.push(`<li><a href="#${id}">${text}</a>`);
|
||||||
|
if (level > currentLevel) {
|
||||||
|
tocItems.push("<ul>");
|
||||||
|
currentLevel = level;
|
||||||
|
} else {
|
||||||
|
tocItems.push("</li>");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while (currentLevel > 0) {
|
||||||
|
tocItems.push("</ul></li>");
|
||||||
|
currentLevel--;
|
||||||
|
}
|
||||||
|
|
||||||
|
tableOfContents = `
|
||||||
|
<details class="table-of-contents">
|
||||||
<summary>Table of contents</summary>
|
<summary>Table of contents</summary>
|
||||||
<ul>
|
${tocItems.join("")}
|
||||||
${headings
|
</details>
|
||||||
.map(
|
`;
|
||||||
({ id, text, level }) => `
|
}
|
||||||
<li><a href="#${id}" class="h${level}">${text}</a></li>`
|
|
||||||
)
|
|
||||||
.join("")}
|
|
||||||
</ul>
|
|
||||||
</details>`
|
|
||||||
: "";
|
|
||||||
|
|
||||||
return `
|
return `
|
||||||
${tableOfContents}
|
${tableOfContents}
|
||||||
|
|||||||
Reference in New Issue
Block a user