-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tsx
137 lines (127 loc) · 3.89 KB
/
main.tsx
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import { copy, Helmet, parseArgs } from "#/deps.ts";
import type { Project } from "#/lib/projects/mod.ts";
import {
renderProjectPageHTML,
renderProjectsPageHTML,
walkProjects,
} from "#/lib/projects/mod.ts";
import {
renderWorkshopGroupPageHTML,
renderWorkshopGroupsPageHTML,
walkWorkshopGroups,
type WorkshopGroup,
} from "#/lib/workshops/mod.ts";
import { withLayout } from "#/lib/shared/layout/mod.ts";
import { PageHeading } from "#/lib/shared/page_heading/mod.ts";
import { join } from "#/deps.ts";
if (import.meta.main) {
await main(Deno.args);
}
// Build script for generating static site from markdown files
// in the projects directory.
async function main(args: string[]) {
const flags = parseArgs(args, {
string: ["indir", "outdir", "staticdir", "base-url"],
alias: {
indir: ["i"],
outdir: ["o"],
staticdir: ["s"],
},
default: {
indir: "./",
outdir: "build",
staticdir: "static",
},
});
// Create projects directory if it does not exist.
await Deno.mkdir(join(flags.outdir, "projects"), { recursive: true });
// Render projects assets.
const projects: Project[] = [];
for await (
const project of walkProjects(join(flags.indir, "projects", "*.md"))
) {
projects.push(project);
const html = renderProjectPageHTML(project, flags["base-url"]);
await Deno.writeTextFile(
join(flags.outdir, "projects", `${project.id}.html`),
html,
);
const json = JSON.stringify(project, null, 2);
await Deno.writeTextFile(
join(flags.outdir, "projects", `${project.id}.json`),
json,
);
}
const projectsIndexHTML = await renderProjectsPageHTML(projects);
await Deno.writeTextFile(
join(flags.outdir, "projects.html"),
projectsIndexHTML,
);
// Create workshops directory if it does not exist.
await Deno.mkdir(join(flags.outdir, "series"), { recursive: true });
// Render workshops assets.
const workshopGroups: WorkshopGroup[] = [];
for await (
const group of walkWorkshopGroups(join(flags.indir, "workshops", "*.md"))
) {
workshopGroups.push(group);
const html = renderWorkshopGroupPageHTML(group, flags["base-url"]);
await Deno.writeTextFile(
join(flags.outdir, "series", `${group.id}.html`),
html,
);
const json = JSON.stringify(group, null, 2);
await Deno.writeTextFile(
join(flags.outdir, "series", `${group.id}.json`),
json,
);
}
const sortedWorkshopGroups = workshopGroups.sort((a, b) => {
const workshopA = new Date(a.workshops[0].timestamp ?? 0);
const workshopB = new Date(b.workshops[0].timestamp ?? 0);
return workshopA.getTime() - workshopB.getTime();
});
const workshopsIndexHTML = renderWorkshopGroupsPageHTML(sortedWorkshopGroups);
await Deno.writeTextFile(
`${flags.outdir}/workshops.html`,
workshopsIndexHTML,
);
await Deno.writeTextFile(
`${flags.outdir}/workshops.json`,
JSON.stringify(workshopGroups, null, 2),
);
// Copy contents of static directory to outdir.
await copy(flags.staticdir, flags.outdir, { overwrite: true });
// Render index page.
await Deno.writeTextFile(
`${flags.outdir}/index.html`,
withLayout(
<main>
<Helmet>
<html lang="en" amp />
<title>Open Source Software docs</title>
<meta
name="description"
content="ACM at CSUF Open Source Software team documentation"
/>
</Helmet>
<PageHeading title="docs" />
<p>
This is a static documentation site for the{" "}
<a href="https://github.com/acmcsufoss">
<strong>@acmcsufoss</strong>
</a>{" "}
organization.
<ul>
<li>
<a href="projects.html">Projects</a>
</li>
<li>
<a href="workshops.html">Workshops</a>
</li>
</ul>
</p>
</main>,
),
);
}