-
-
Notifications
You must be signed in to change notification settings - Fork 37
/
build-search.ts
56 lines (53 loc) · 1.34 KB
/
build-search.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
import { fs, mustache, path } from "./deps.ts";
import {
getConfig,
getPublicPath,
readTextFile,
writeTextFile,
} from "./util.ts";
import { RunOptions } from "./interface.ts";
export default async function buildSearch(runOptions: RunOptions) {
const config = runOptions.config;
const sourcesConfig = config.sources;
const siteConfig = config.site;
const htmlSearchTemplateContent = await readTextFile(
"./templates/search.html.mu",
);
// copy search index
await fs.copy(
"./temp-morsels/",
path.join(getPublicPath(), "search-index/"),
{
overwrite: true,
},
);
const searchPageData = {
title: "Search Awesome Projects",
_site_title: siteConfig.title,
description: config.site.description,
_seo_title: `Search Awesome Projects - ${config.site.title}`,
home_page_url: config.site.url + "/search/",
};
const searchHtmlDoc = mustache.render(
htmlSearchTemplateContent,
searchPageData,
);
const htmlSearchPath = path.join(
getPublicPath(),
"search/index.html",
);
await writeTextFile(htmlSearchPath, searchHtmlDoc);
}
if (import.meta.main) {
const config = await getConfig();
await buildSearch({
config,
sourceIdentifiers: [],
fetchRepoUpdates: false,
markdown: false,
fetch: false,
dayMarkdown: false,
serve: false,
port: 8000,
});
}