Skip to content

Commit 571e687

Browse files
✨ Support for markdown links in navbar
1 parent f632159 commit 571e687

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@staart/site",
3-
"version": "0.9.60",
3+
"version": "0.9.61",
44
"module": "dist/module.js",
55
"main": "dist/index.js",
66
"bin": "./dist/index.js",

src/data.ts

+12-5
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,19 @@ export const getSiteMeta = async (
1919
};
2020

2121
export const getNavbar = async (files?: string[]) => {
22-
if (!files) files = await listRootFiles();
23-
files = files.sort((a, b) => a.localeCompare(b));
22+
if (!files)
23+
files = (await listRootFiles())
24+
.sort((a, b) => a.localeCompare(b))
25+
.reverse();
2426
let data = "";
2527
for await (const file of files) {
26-
const md = await readContentFile(file);
27-
const title = await getTitle(md);
28-
data += `- [${title}](/${file.replace(".md", ".html")})\n`;
28+
if (file.startsWith("[")) {
29+
data += `- ${file}\n`;
30+
} else {
31+
const md = await readContentFile(file);
32+
const title = await getTitle(md);
33+
data += `- [${title}](/${file.replace(".md", ".html")})\n`;
34+
}
2935
}
3036
return data;
3137
};
@@ -35,6 +41,7 @@ export const getData = async () => {
3541
const config = await getConfig();
3642
config.data = config.data || {};
3743
config.data.rootFiles = await getNavbar();
44+
config.data.navBar = await getNavbar(config.navbar);
3845
if (!config.ignoreReplaceTitle)
3946
config.data.title = await getSiteMeta("title", "name");
4047
if (!config.ignoreReplaceDescription)

src/generator.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,7 @@ export const generate = async () => {
136136
const generateSitemap = async () => {
137137
const files = await listContentFiles();
138138
const config = await getConfig();
139-
let content =
140-
(await getSitemapContent()) +
141-
"\n\n" +
142-
(config.navbar || (await getNavbar(files)));
139+
let content = (await getSitemapContent()) + "\n\n" + (await getNavbar(files));
143140
await generatePage("sitemap.html", content);
144141
const sitemap = new SitemapStream({
145142
hostname: config.hostname || "http://localhost:8080"

src/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ <h1>{{ title }}</h1>
2727
</div>
2828
<nav>
2929
<div>
30-
{{{ rootFiles }}}
30+
{{{ navBar }}}
3131
</div>
3232
</nav>
3333
</header>

0 commit comments

Comments
 (0)