forked from qwik/qwik-site
Added site map for /articles.
This commit is contained in:
parent
b277f15e46
commit
292fa46e1b
|
@ -19,4 +19,8 @@ body {
|
||||||
.sitemap-dir > .sitemap-dir {
|
.sitemap-dir > .sitemap-dir {
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
padding: 0 0 .5rem 1rem;
|
padding: 0 0 .5rem 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sitemap-dir a {
|
||||||
|
display: block;
|
||||||
}
|
}
|
19
content/pages/articles.njk
Normal file
19
content/pages/articles.njk
Normal 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>
|
|
@ -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>`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user