From 292fa46e1b50f1b0d965e649ddd2e97b076e27b2 Mon Sep 17 00:00:00 2001 From: BurnyLlama Date: Tue, 10 Aug 2021 20:51:11 +0200 Subject: [PATCH] Added site map for /articles. --- assets/css/sitemap.css | 4 ++++ content/pages/articles.njk | 19 +++++++++++++++++++ libs/utils/siteMap.js | 11 +++++++---- 3 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 content/pages/articles.njk diff --git a/assets/css/sitemap.css b/assets/css/sitemap.css index 0ef2bd5..d3d1e4a 100644 --- a/assets/css/sitemap.css +++ b/assets/css/sitemap.css @@ -19,4 +19,8 @@ body { .sitemap-dir > .sitemap-dir { margin: 0 auto; padding: 0 0 .5rem 1rem; +} + +.sitemap-dir a { + display: block; } \ No newline at end of file diff --git a/content/pages/articles.njk b/content/pages/articles.njk new file mode 100644 index 0000000..e13b603 --- /dev/null +++ b/content/pages/articles.njk @@ -0,0 +1,19 @@ + + + + {% include "templates/defaultTags.njk" %} + + Site Map + + +
+ All Articles +
+

+ Here's a list of all articles: +

+
+ {{ siteMap("/articles") | safe }} +
+ + \ No newline at end of file diff --git a/libs/utils/siteMap.js b/libs/utils/siteMap.js index 270a80e..9a85dc6 100644 --- a/libs/utils/siteMap.js +++ b/libs/utils/siteMap.js @@ -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(`${dir.address}`) + result.push(`${dir.path}`) result.push(renderSiteMap(dir.children, entrypoint)) result.push(``) } else { - result.push(`${dir.address}`) + result.push(`${dir.path}`) } }