Added site map for /articles.

This commit is contained in:
BurnyLlama 2021-08-10 20:51:11 +02:00
parent b277f15e46
commit 292fa46e1b
3 changed files with 30 additions and 4 deletions

View File

@ -20,3 +20,7 @@ body {
margin: 0 auto; margin: 0 auto;
padding: 0 0 .5rem 1rem; padding: 0 0 .5rem 1rem;
} }
.sitemap-dir a {
display: block;
}

View File

@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="en">
<head>
{% include "templates/defaultTags.njk" %}
<link rel="stylesheet" type="text/css" href="/assets/css/sitemap.css">
<title>Site Map</title>
</head>
<body>
<header>
All Articles
</header>
<p class="centered">
Here's a list of all articles:
</p>
<div class="sitemap-container">
{{ siteMap("/articles") | safe }}
</div>
</body>
</html>

View File

@ -15,14 +15,17 @@ async function handlePath(dirName, siteMap) {
if (fileStats.isDirectory()) if (fileStats.isDirectory())
siteMap[fullPath.replace(/^[\s\S]+\/pages/, "")] = { siteMap[fullPath.replace(/^[\s\S]+\/pages/, "")] = {
path: fullPath, path: fullPath.replace(/^[\s\S]+\/pages/, "").replace(/\/.+\//, "/"),
address: fullPath.replace(/^[\s\S]+\/pages/, ""), address: fullPath.replace(/^[\s\S]+\/pages/, ""),
type: "directory", type: "directory",
children: await handlePath(fullPath, {}) children: await handlePath(fullPath, {})
} }
else else
// Check if it already exists
siteMap[fullPath.replace(/^[\s\S]+\/pages/, "").replace(/\.[a-z]+$/, "")] ?
siteMap[fullPath.replace(/^[\s\S]+\/pages/, "").replace(/\.[a-z]+$/, "")] :
siteMap[fullPath.replace(/^[\s\S]+\/pages/, "").replace(/\.[a-z]+$/, "")] = { siteMap[fullPath.replace(/^[\s\S]+\/pages/, "").replace(/\.[a-z]+$/, "")] = {
path: fullPath, path: fullPath.replace(/^[\s\S]+\/pages/, "").replace(/\.[a-z]+$/, "").replace(/\/.+\//, "/"),
address: fullPath.replace(/^[\s\S]+\/pages/, "").replace(/\.[a-z]+$/, ""), address: fullPath.replace(/^[\s\S]+\/pages/, "").replace(/\.[a-z]+$/, ""),
type: "file" type: "file"
} }
@ -45,11 +48,11 @@ function renderSiteMap(siteMap, entrypoint) {
continue continue
if (dir.type === "directory") { if (dir.type === "directory") {
result.push(`<a href="${dir.address}">${dir.address}`) result.push(`<a href="${dir.address}">${dir.path}`)
result.push(renderSiteMap(dir.children, entrypoint)) result.push(renderSiteMap(dir.children, entrypoint))
result.push(`</a>`) result.push(`</a>`)
} else { } else {
result.push(`<a href="${dir.address}">${dir.address}</a>`) result.push(`<a href="${dir.address}">${dir.path}</a>`)
} }
} }