|
1 |
| -import { ensureDir, readFile, writeFile } from "fs-extra"; |
| 1 | +import { ensureDir, readFile, writeFile, ensureFile } from "fs-extra"; |
2 | 2 | import {
|
3 | 3 | getDistPath,
|
4 | 4 | getTemplatePath,
|
5 | 5 | getStylePath,
|
6 | 6 | getHomePath,
|
7 | 7 | getContentPath,
|
8 |
| - listContentFiles |
| 8 | + listContentFiles, |
| 9 | + readContentFile |
9 | 10 | } from "./files";
|
10 | 11 | import { cached } from "./cache";
|
11 |
| -import { join } from "path"; |
| 12 | +import { join, parse } from "path"; |
12 | 13 | import { compile } from "handlebars";
|
13 | 14 | import { getData, render, getNavbar } from "./data";
|
14 | 15 | import { minify } from "html-minifier";
|
@@ -83,6 +84,21 @@ export const generate = async () => {
|
83 | 84 | const config = await getConfig();
|
84 | 85 | if (!config.noHome) await generatePage("index.html", await getHomeContent());
|
85 | 86 | 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 | + } |
86 | 102 | };
|
87 | 103 |
|
88 | 104 | const generateSitemap = async () => {
|
@@ -124,6 +140,7 @@ const generatePage = async (path: string, content: string) => {
|
124 | 140 | }
|
125 | 141 | data.css = await getCss();
|
126 | 142 | const result = template(data);
|
| 143 | + await ensureFile(join(await getDistPath(), path)); |
127 | 144 | await writeFile(
|
128 | 145 | join(await getDistPath(), path),
|
129 | 146 | minify(result, {
|
|
0 commit comments