Added site map for /articles.

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

View File

@ -19,4 +19,8 @@ body {
.sitemap-dir > .sitemap-dir {
margin: 0 auto;
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())
siteMap[fullPath.replace(/^[\s\S]+\/pages/, "")] = {
path: fullPath,
path: fullPath.replace(/^[\s\S]+\/pages/, "").replace(/\/.+\//, "/"),
address: fullPath.replace(/^[\s\S]+\/pages/, ""),
type: "directory",
children: await handlePath(fullPath, {})
}
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]+$/, "")] = {
path: fullPath,
path: fullPath.replace(/^[\s\S]+\/pages/, "").replace(/\.[a-z]+$/, "").replace(/\/.+\//, "/"),
address: fullPath.replace(/^[\s\S]+\/pages/, "").replace(/\.[a-z]+$/, ""),
type: "file"
}
@ -45,11 +48,11 @@ function renderSiteMap(siteMap, entrypoint) {
continue
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(`</a>`)
} else {
result.push(`<a href="${dir.address}">${dir.address}</a>`)
result.push(`<a href="${dir.address}">${dir.path}</a>`)
}
}