-
Notifications
You must be signed in to change notification settings - Fork 14
/
render-staff-site.ts
112 lines (84 loc) · 3.36 KB
/
render-staff-site.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
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
import { parse, stringify } from "https://deno.land/std/yaml/mod.ts";
import { join, dirname, basename } from "https://deno.land/std/path/mod.ts";
const configPath = '_config.yml'; // Path to your config YAML file
const schedulePath = 'schedule.yml';
// This is the same as full-render.ts except it activates the staff-site profile
// in the last step.
// ---------------------------------------- //
// Make schedule.yml with all render: true //
// ---------------------------------------- //
async function makeFullSchedule(configPath: string, schedulePath: string) {
const yamlContent = await Deno.readTextFile(configPath);
const config = parse(yamlContent) as any;
if (config && config.schedule) {
const updatedSchedule = config.schedule.map(week => ({
...week,
days: week.days.map(day => ({
...day,
items: day.items ? day.items.map(item => ({
...item,
render: true // Set render to true for all items
})) : []
}))
}));
await Deno.writeTextFile(schedulePath, stringify(updatedSchedule));
}
}
console.log("> Making schedule file ...");
await makeFullSchedule(configPath, schedulePath);
// ----------------------------------- //
// Make Sidebar Nav from schedule //
// ----------------------------------- //
async function makeSidebarNav(schedulePath: string, configPath: string) {
const scheduleContent = await Deno.readTextFile(schedulePath);
const schedule = parse(scheduleContent) as Array<any>;
const configContent = await Deno.readTextFile(configPath);
const config = parse(configContent) as any;
const sidebarTypes = config['adaptive-nav']['sidebar'];
const isHybridMode = config['adaptive-nav']?.hybrid || false;
let sidebarContents = [];
sidebarTypes.forEach(sidebarType => {
const type = sidebarType.type;
let typeHrefs: string[] = [];
schedule.forEach(week => {
week.days.forEach(day => {
day.items.forEach(item => {
if (item.type === type && item.render) {
typeHrefs.push(item.href);
}
});
});
});
if (isHybridMode) {
sidebarContents.push({ title: type, contents: typeHrefs });
} else {
sidebarContents.push({ section: type, contents: typeHrefs });
}
});
const sidebarNav = {
website: {
sidebar: isHybridMode ? sidebarContents : { contents: sidebarContents }
}
};
const sidebarNavPath = join(dirname(schedulePath), 'sidebar-nav.yml');
await Deno.writeTextFile(sidebarNavPath, stringify(sidebarNav));
}
console.log("> Making extra sidebar nav...")
await makeSidebarNav(schedulePath, configPath);
// -------------------------------- //
// Render staff site //
// -------------------------------- //
async function runQuartoRender() {
const process = Deno.run({
cmd: ["quarto", "render", "--profile", "staff-site"],
stdout: "inherit",
stderr: "inherit",
});
const { code } = await process.status();
if (code !== 0) {
console.error('Error: Quarto render process exited with code', code);
}
process.close();
}
console.log("> Full render list has been made.");
await runQuartoRender();