diff --git a/assets/css/sitemap.css b/assets/css/sitemap.css
new file mode 100644
index 0000000..0ef2bd5
--- /dev/null
+++ b/assets/css/sitemap.css
@@ -0,0 +1,22 @@
+body {
+ display: flex;
+ flex-direction: column;
+}
+
+.sitemap-container {
+ display: grid;
+ place-items: center;
+
+ width: fit-content;
+
+ margin: 2rem auto;
+ padding: 1rem 4rem;
+ background-color: var(--grey3);
+ border-radius: .5rem;
+ box-shadow: 0 1rem 2rem var(--grey1);
+}
+
+.sitemap-dir > .sitemap-dir {
+ margin: 0 auto;
+ padding: 0 0 .5rem 1rem;
+}
\ No newline at end of file
diff --git a/content/pages/sitemap.njk b/content/pages/sitemap.njk
new file mode 100644
index 0000000..9bdf417
--- /dev/null
+++ b/content/pages/sitemap.njk
@@ -0,0 +1,16 @@
+
+
+
+ {% include "templates/defaultTags.njk" %}
+
+ Site Map
+
+
+
+
+ {{ siteMap() | safe }}
+
+
+
\ No newline at end of file
diff --git a/index.js b/index.js
index f928620..b49297a 100644
--- a/index.js
+++ b/index.js
@@ -2,11 +2,10 @@ import fs from 'fs'
import express from 'express'
import njk from 'nunjucks'
-import njkMarkdown from 'nunjucks-markdown'
-import marked from 'marked'
import { requestHandler } from './libs/requestHandler.js'
-import { markedRenderer } from './libs/markedRenderer.js'
+import { utils } from './libs/utils/utils.js'
+import { nunjacksConfig } from './libs/nunjucksConfig.js'
// Load in config
@@ -23,26 +22,11 @@ const Server = express()
// Configure the assets directory
Server.use('/assets', express.static(Config.assetsDir))
-// Configure the nunjucks environment (HTML templating)
-const njkEnv = njk.configure(
- Config.contentDir,
- {
- autoescape: true, // Automatically escape HTML aka a '<' will become '<'
- watch: true, // Automatically reload all templates if they change on disk.
- trimBlocks: true, // Remove trailing newlines from tags
- lstripBlocks: true, // Automatically remove leading whitespace from tags
- express: Server // Use the express server. (Currently obsolete, I think.)
- }
-)
+// Configure nunjacks
+nunjacksConfig(njk, Server, Config)
-// Configure marked (markdown parser)
-marked.use({
- gfm: true, // Use GitHub formatting?
- renderer: markedRenderer // Use my own custom rendering for som tags
-})
-
-// Let nunjucks use markdown.
-njkMarkdown.register(njkEnv, marked)
+// Generate utils
+utils.generate()
diff --git a/libs/nunjucksConfig.js b/libs/nunjucksConfig.js
new file mode 100644
index 0000000..d313d63
--- /dev/null
+++ b/libs/nunjucksConfig.js
@@ -0,0 +1,31 @@
+import njkMarkdown from 'nunjucks-markdown'
+import marked from 'marked'
+
+import { markedRenderer } from './markedRenderer.js'
+import { utils } from './utils/utils.js'
+
+
+export function nunjacksConfig(njk, express, Config) {
+ // Configure the nunjucks environment (HTML templating)
+ const njkEnv = njk.configure(
+ Config.contentDir,
+ {
+ autoescape: true, // Automatically escape HTML aka a '<' will become '<'
+ watch: true, // Automatically reload all templates if they change on disk.
+ trimBlocks: true, // Remove trailing newlines from tags
+ lstripBlocks: true, // Automatically remove leading whitespace from tags
+ express: express // Use the express server. (Currently obsolete, I think.)
+ }
+ )
+
+ njkEnv.addGlobal('siteMap', entrypoint => utils.values.siteMap.render(entrypoint ? entrypoint : "/"))
+
+ // Configure marked (markdown parser)
+ marked.use({
+ gfm: true, // Use GitHub formatting?
+ renderer: markedRenderer // Use my own custom rendering for som tags
+ })
+
+ // Let nunjucks use markdown.
+ njkMarkdown.register(njkEnv, marked)
+}
\ No newline at end of file
diff --git a/libs/utils/siteMap.js b/libs/utils/siteMap.js
new file mode 100644
index 0000000..270a80e
--- /dev/null
+++ b/libs/utils/siteMap.js
@@ -0,0 +1,70 @@
+import fs from 'fs/promises'
+import path from 'path'
+
+async function handlePath(dirName, siteMap) {
+ // Get all directories in the 'dirName'
+ const dirs = await fs.readdir(dirName)
+
+ // For each file in the directory: check if it is a
+ // file or a folder, if a folder recursively run this
+ // function in that folder.
+ for (const dirIndex in dirs) {
+ const file = dirs[dirIndex]
+ const fullPath = path.join(dirName, file)
+ const fileStats = await fs.stat(fullPath)
+
+ if (fileStats.isDirectory())
+ siteMap[fullPath.replace(/^[\s\S]+\/pages/, "")] = {
+ path: fullPath,
+ address: fullPath.replace(/^[\s\S]+\/pages/, ""),
+ type: "directory",
+ children: await handlePath(fullPath, {})
+ }
+ else
+ siteMap[fullPath.replace(/^[\s\S]+\/pages/, "").replace(/\.[a-z]+$/, "")] = {
+ path: fullPath,
+ address: fullPath.replace(/^[\s\S]+\/pages/, "").replace(/\.[a-z]+$/, ""),
+ type: "file"
+ }
+ }
+
+ return siteMap
+}
+
+function renderSiteMap(siteMap, entrypoint) {
+ // Make a template for the sitemap and recursively run
+ // for all directories with children.
+ return `
+
+ `
+}
+
+export async function generateSiteMap(Config) {
+ // Generate a site map and return it and a render-function.
+ const siteMap = await handlePath(`${Config.contentDir}/pages`, {})
+
+ return {
+ siteMap,
+ render: entrypoint => renderSiteMap(siteMap, entrypoint)
+ }
+}
\ No newline at end of file
diff --git a/libs/utils/utils.js b/libs/utils/utils.js
new file mode 100644
index 0000000..1f0dfc9
--- /dev/null
+++ b/libs/utils/utils.js
@@ -0,0 +1,14 @@
+import fs from 'fs'
+import { generateSiteMap } from './siteMap.js'
+
+const ConfigFile = fs.readFileSync('./config.json')
+const Config = JSON.parse(ConfigFile)
+
+// Generate some utilities
+export let utils = {
+ generate: async () =>
+ utils.values = {
+ siteMap: await generateSiteMap(Config)
+ },
+ values: {}
+}
\ No newline at end of file