Skip to content

Commit 1a6b8b4

Browse files
✨ Add content listing
1 parent 3b9c65c commit 1a6b8b4

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
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.49",
3+
"version": "0.9.50",
44
"main": "dist/index.js",
55
"bin": "./dist/index.js",
66
"repository": "[email protected]:staart/site",

src/generator.ts

+20-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
import { ensureDir, readFile, writeFile } from "fs-extra";
1+
import { ensureDir, readFile, writeFile, ensureFile } from "fs-extra";
22
import {
33
getDistPath,
44
getTemplatePath,
55
getStylePath,
66
getHomePath,
77
getContentPath,
8-
listContentFiles
8+
listContentFiles,
9+
readContentFile
910
} from "./files";
1011
import { cached } from "./cache";
11-
import { join } from "path";
12+
import { join, parse } from "path";
1213
import { compile } from "handlebars";
1314
import { getData, render, getNavbar } from "./data";
1415
import { minify } from "html-minifier";
@@ -83,6 +84,21 @@ export const generate = async () => {
8384
const config = await getConfig();
8485
if (!config.noHome) await generatePage("index.html", await getHomeContent());
8586
if (!config.noSitemap) await generateSitemap();
87+
const files = (await listContentFiles()).filter(
88+
file => !["index.md", "sitemap.md"].includes(file)
89+
);
90+
for await (const file of files) {
91+
let content = await readContentFile(file);
92+
if (parse(file).name === "index" && !config.noContentList) {
93+
const deepFiles = (await listContentFiles(join(file, "..")))
94+
.filter(f => f !== "index.md")
95+
.map(f => join(file, "..", f));
96+
if (deepFiles.length) {
97+
content += "\n\n" + (await getNavbar(deepFiles));
98+
}
99+
}
100+
await generatePage(file.replace(".md", ".html"), content);
101+
}
86102
};
87103

88104
const generateSitemap = async () => {
@@ -124,6 +140,7 @@ const generatePage = async (path: string, content: string) => {
124140
}
125141
data.css = await getCss();
126142
const result = template(data);
143+
await ensureFile(join(await getDistPath(), path));
127144
await writeFile(
128145
join(await getDistPath(), path),
129146
minify(result, {

src/interfaces.ts

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export interface StaartSiteConfig {
1919
ignoreReplaceYear?: boolean;
2020
noHome?: boolean;
2121
noSitemap?: boolean;
22+
noContentList?: boolean;
2223
[index: string]: any;
2324
}
2425

0 commit comments

Comments
 (0)