forked from trackawesomelist/trackawesomelist-source
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-html.ts
86 lines (83 loc) · 2.23 KB
/
build-html.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import { CSS, groupBy, jsonfeedToAtom, mustache } from "./deps.ts";
import { fs, path } from "./deps.ts";
import {
DayInfo,
FeedInfo,
File,
FileInfo,
FileMetaWithSource,
Item,
List,
ListItem,
RunOptions,
WeekOfYear,
} from "./interface.ts";
import renderMarkdown from "./render-markdown.ts";
import {
INDEX_MARKDOWN_PATH,
SUBSCRIPTION_URL,
TOP_REPOS_COUNT,
} from "./constant.ts";
import {
exists,
formatHumanTime,
getBaseFeed,
getDayNumber,
getDbIndex,
getDbMeta,
getDistRepoContentPath,
getDistRepoGitUrl,
getDistRepoPath,
getIndexFileConfig,
getnextPaginationTextByNumber,
getPublicPath,
getRepoHTMLURL,
getStaticPath,
getWeekNumber,
pathnameToFeedUrl,
pathnameToFilePath,
readTextFile,
slug,
walkFile,
writeDbMeta,
writeJSONFile,
writeTextFile,
} from "./util.ts";
import log from "./log.ts";
import { getItemsByDays, getUpdatedDays, getUpdatedFiles } from "./db.ts";
import buildBySource from "./build-by-source.ts";
import buildByTime, { itemsToFeedItemsByDate } from "./build-by-time.ts";
export default async function buildHtml(options: RunOptions) {
const config = options.config;
const sourcesConfig = config.sources;
const sourcesKeys = Object.keys(sourcesConfig);
const isBuildSite = options.html;
const specificSourceIdentifiers = options.sourceIdentifiers;
if (isBuildSite) {
const htmlIndexTemplateContent = await readTextFile(
"./templates/index.html.mu",
);
// build from markdown
const markdownPath = getDistRepoContentPath();
for await (const entry of await walkFile(markdownPath)) {
const { path: filePath, isFile } = entry;
if (isFile && filePath.endsWith(".md")) {
const relativePath = path.relative(path.join(markdownPath), filePath);
const file = await readTextFile(filePath);
const html = renderMarkdown(file);
const htmlPath = path.join(
getPublicPath(),
relativePath.replace(/README\.md$/, "index.html"),
);
// const htmlDoc = mustache.render(htmlIndexTemplateContent, {
// ...indexFeed,
// body: html,
// CSS,
// });
await writeTextFile(htmlPath, html);
}
}
} else {
log.info("skip build html...");
}
}