@allons-y/course-kit 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +373 -0
- package/README.md +90 -2
- package/assets/fonts/instrument-sans-italic-var.woff2 +0 -0
- package/assets/fonts/instrument-sans-var.woff2 +0 -0
- package/assets/fonts/pt-mono.woff2 +0 -0
- package/assets/scripts/copy.js +99 -0
- package/assets/scripts/deck.js +161 -0
- package/assets/scripts/email.js +17 -0
- package/assets/scripts/practice.js +545 -0
- package/assets/scripts/theme-panel.js +647 -0
- package/assets/scripts/theme-restore.js +17 -0
- package/assets/styles/base.css +2090 -0
- package/assets/styles/deck.css +968 -0
- package/assets/styles/font.css +36 -0
- package/assets/styles/notes.css +137 -0
- package/assets/styles/print.css +428 -0
- package/assets/styles/semantics.css +101 -0
- package/components/practice/check-controls.webc +50 -0
- package/components/practice/choice-list.webc +86 -0
- package/components/practice/cite-panel.webc +108 -0
- package/components/practice/practice-figure.webc +47 -0
- package/components/practice/practice-fill.webc +154 -0
- package/components/practice/practice-grid.webc +82 -0
- package/components/practice/practice-judge.webc +165 -0
- package/components/practice/practice-match.webc +178 -0
- package/components/practice/practice-question.webc +141 -0
- package/components/practice/practice-selfcheck.webc +40 -0
- package/components/practice/practice-terms.webc +95 -0
- package/components/practice/practice-tree.webc +91 -0
- package/components/practice/practice-worksheet.webc +369 -0
- package/components/site/copyright.webc +13 -0
- package/components/site/course-documents.webc +27 -0
- package/components/site/course-now.webc +393 -0
- package/components/site/course-summary.webc +136 -0
- package/components/site/demo-weeks.webc +91 -0
- package/components/site/glossary-entry.webc +31 -0
- package/components/site/glossary-panel.webc +1482 -0
- package/components/site/glossary.webc +45 -0
- package/components/site/grading.webc +50 -0
- package/components/site/instructor.webc +269 -0
- package/components/site/masthead.webc +147 -0
- package/components/site/nav-links.webc +174 -0
- package/components/site/policies.webc +17 -0
- package/components/site/practice-index.webc +31 -0
- package/components/site/schedule-overview.webc +145 -0
- package/components/site/schedule-weeks.webc +589 -0
- package/components/site/site-footer.webc +119 -0
- package/components/site/slide-timetable.webc +152 -0
- package/components/site/syllabus.webc +217 -0
- package/components/ui/arrow-link.webc +19 -0
- package/components/ui/assigned-list.webc +101 -0
- package/components/ui/callout.webc +11 -0
- package/components/ui/card-list.webc +124 -0
- package/components/ui/codepen-embed.webc +123 -0
- package/components/ui/download-button.webc +49 -0
- package/components/ui/eyebrow.webc +18 -0
- package/components/ui/icons/github.webc +6 -0
- package/components/ui/icons/google.webc +9 -0
- package/components/ui/link-list.webc +130 -0
- package/components/ui/link-section.webc +40 -0
- package/components/ui/meeting-card.webc +73 -0
- package/components/ui/meeting-decks.webc +38 -0
- package/components/ui/table-rubric.webc +251 -0
- package/components/ui/today-link.webc +43 -0
- package/components/ui/today-marker.webc +149 -0
- package/components/ui/week-block.webc +53 -0
- package/examples/starter/_data/course.json +20 -0
- package/examples/starter/_data/dates.json +16 -0
- package/examples/starter/_data/grading.json +6 -0
- package/examples/starter/_data/instructor.json +7 -0
- package/examples/starter/_data/policies.json +9 -0
- package/examples/starter/_data/scale.json +8 -0
- package/examples/starter/_data/schedule.json +22 -0
- package/examples/starter/_data/theme.json +17 -0
- package/examples/starter/content/index.webc +12 -0
- package/examples/starter/content/schedule.webc +12 -0
- package/examples/starter/content/slides/index.11tydata.js +5 -0
- package/examples/starter/content/slides/index.webc +12 -0
- package/examples/starter/content/slides/week-1-day-1.md +40 -0
- package/examples/starter/eleventy.config.js +8 -0
- package/glue/deck-notes.data.js +41 -0
- package/glue/deck-notes.webc +32 -0
- package/glue/lesson-day.data.js +17 -0
- package/glue/lesson-day.webc +0 -0
- package/glue/lesson-plans.data.js +13 -0
- package/glue/lesson-plans.webc +2 -0
- package/index.js +6 -0
- package/layouts/base.webc +79 -0
- package/layouts/deck.webc +46 -0
- package/layouts/demo.webc +16 -0
- package/layouts/document.webc +10 -0
- package/layouts/lesson-detail.webc +109 -0
- package/layouts/lesson.webc +71 -0
- package/layouts/notes.webc +23 -0
- package/layouts/worksheet.webc +52 -0
- package/lib/assets.js +42 -0
- package/lib/bundles.js +79 -0
- package/lib/check.js +110 -0
- package/lib/components.js +19 -0
- package/lib/copy.js +653 -0
- package/lib/data/build.js +22 -0
- package/lib/data/fonts.js +16 -0
- package/lib/data/glossary.js +304 -0
- package/lib/data/index.js +8 -0
- package/lib/data/lessons.js +173 -0
- package/lib/data/project.js +22 -0
- package/lib/data/read.js +46 -0
- package/lib/data/site.js +70 -0
- package/lib/data/term.js +80 -0
- package/lib/extensions.js +70 -0
- package/lib/files.js +14 -0
- package/lib/filters.js +584 -0
- package/lib/fit.js +106 -0
- package/lib/glue.js +26 -0
- package/lib/lesson-materials.js +66 -0
- package/lib/markdown.js +568 -0
- package/lib/minify.js +53 -0
- package/lib/paths.js +5 -0
- package/lib/pdf.js +134 -0
- package/lib/plugin.js +228 -0
- package/lib/plugins.js +34 -0
- package/lib/postcss.js +93 -0
- package/lib/theme-server.js +88 -0
- package/lib/theme.js +185 -0
- package/lib/worksheet-dialect.js +415 -0
- package/lib/worksheets.js +276 -0
- package/package.json +118 -4
- package/schemas/course.schema.json +156 -0
- package/schemas/dates.schema.json +165 -0
- package/schemas/grading.schema.json +59 -0
- package/schemas/instructor.schema.json +68 -0
- package/schemas/policies.schema.json +90 -0
- package/schemas/project.schema.json +209 -0
- package/schemas/scale.schema.json +68 -0
- package/schemas/schedule.schema.json +260 -0
- package/schemas/theme.schema.json +704 -0
- package/schemas/worksheet.schema.json +449 -0
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The course glossary: every `vocab` and `api` slide as one term, tagged by
|
|
3
|
+
* test, chapter and class meeting. Read from the decks, so a new slide
|
|
4
|
+
* appears here on the next build. Nothing here depends on the date.
|
|
5
|
+
*/
|
|
6
|
+
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
7
|
+
import { join } from "node:path";
|
|
8
|
+
|
|
9
|
+
import { dateFormat } from "@allons-y/dashly/filters/dates";
|
|
10
|
+
import matter from "gray-matter";
|
|
11
|
+
import markdownIt from "markdown-it";
|
|
12
|
+
|
|
13
|
+
import { COPY_DEFAULTS } from "../copy.js";
|
|
14
|
+
import { fullDate } from "../filters.js";
|
|
15
|
+
|
|
16
|
+
const DECK = /^week-(\d+)-day-(\d+)(?:-[\w-]+)?\.md$/;
|
|
17
|
+
const TEST = /^Test (\d+)$/;
|
|
18
|
+
const noChapter = (copy) => ({ key: "none", label: copy.glossary.slidesOnly, order: 9999 });
|
|
19
|
+
const MONTH_DAY = { month: "long", day: "numeric" };
|
|
20
|
+
const md = markdownIt({ html: true, typographer: true, linkify: true });
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @typedef {object} Tag
|
|
24
|
+
* @property {string} key
|
|
25
|
+
* @property {string} label
|
|
26
|
+
* @property {number} order
|
|
27
|
+
* @property {string} [date] ISO date (test, final exam, meeting)
|
|
28
|
+
* @property {string} [when] the date for display
|
|
29
|
+
* @property {string} [deck] deck title (meeting)
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/** @param {string} text */
|
|
33
|
+
const plain = (text) => text.replace(/[`*_]/g, "").trim();
|
|
34
|
+
|
|
35
|
+
/** @param {string} text */
|
|
36
|
+
const slug = (text) => text.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The sort key of a term: its letters and digits only, lowercased and without
|
|
40
|
+
* accents, so `@supports` sorts beside `supports` and `::before` under B.
|
|
41
|
+
* Empty for a term with no letter or digit (`=>`, `<?=`).
|
|
42
|
+
* @param {string} text
|
|
43
|
+
*/
|
|
44
|
+
const sortKey = (text) => text.normalize("NFKD").toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The A to Z group a sort key belongs to: "0 to 9", a letter, or "Symbols".
|
|
48
|
+
* @param {string} key
|
|
49
|
+
* @returns {{ key: string, label: string }}
|
|
50
|
+
*/
|
|
51
|
+
const azGroupOf = (key, symbols = COPY_DEFAULTS.glossary.symbols) => {
|
|
52
|
+
if (!key) return { key: "symbols", label: symbols };
|
|
53
|
+
if (/^\d/.test(key)) return { key: "0-9", label: "0 to 9" };
|
|
54
|
+
return { key: key[0], label: key[0].toUpperCase() };
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* A to Z order: by sort key (symbols-only terms last), ties broken by the full term.
|
|
59
|
+
* @param {{ key: string, plain: string }} a
|
|
60
|
+
* @param {{ key: string, plain: string }} b
|
|
61
|
+
*/
|
|
62
|
+
const byAz = (a, b) => Number(!a.key) - Number(!b.key) || (a.key < b.key ? -1 : a.key > b.key ? 1 : 0) || a.plain.localeCompare(b.plain, "en") || (a.plain < b.plain ? -1 : Number(a.plain > b.plain));
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Stable id for a term key: its slug, or the code points when the slug is
|
|
66
|
+
* empty or already taken (symbol-only terms like `=>` and `<?=`).
|
|
67
|
+
* @param {string} key
|
|
68
|
+
* @param {Set<string>} taken ids already issued
|
|
69
|
+
* @returns {string}
|
|
70
|
+
*/
|
|
71
|
+
const idFor = (key, taken) => {
|
|
72
|
+
const hex = [...key].map((char) => char.codePointAt(0).toString(16)).join("-");
|
|
73
|
+
const id = slug(key) && !taken.has(slug(key)) ? slug(key) : `${slug(key)}-${hex}`.replace(/^-/, "");
|
|
74
|
+
taken.add(id);
|
|
75
|
+
return id;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Body of the first `::: name` container, or "".
|
|
80
|
+
* @param {string} body
|
|
81
|
+
* @param {string} name
|
|
82
|
+
*/
|
|
83
|
+
const block = (body, name) => body.match(new RegExp(`^::: ${name}[^\\n]*\\n([\\s\\S]*?)^:::\\s*$`, "m"))?.[1].trim() ?? "";
|
|
84
|
+
|
|
85
|
+
/** @param {string} text */
|
|
86
|
+
const inline = (text) => (text ? md.renderInline(text) : "");
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* The tests, from the meetings whose topics hold the exact string "Test n",
|
|
90
|
+
* plus the final exam that follows the last one.
|
|
91
|
+
* @param {ReturnType<typeof lessons>} meetings
|
|
92
|
+
* @returns {Tag[]}
|
|
93
|
+
*/
|
|
94
|
+
const testsFrom = (meetings) => {
|
|
95
|
+
const tests = [];
|
|
96
|
+
for (const meeting of meetings) {
|
|
97
|
+
if (meeting.noClass) continue;
|
|
98
|
+
const label = meeting.topics.find((topic) => TEST.test(topic));
|
|
99
|
+
if (label) tests.push({ key: `test-${label.match(TEST)[1]}`, label, order: Number(label.match(TEST)[1]), date: meeting.date, when: fullDate(meeting.date) });
|
|
100
|
+
}
|
|
101
|
+
return tests.sort((a, b) => a.date.localeCompare(b.date));
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* The tag a term gets when its meeting is on or before a test, else the final exam.
|
|
106
|
+
* @param {Tag[]} tests
|
|
107
|
+
* @param {string} date
|
|
108
|
+
* @param {object} schedule for the final exam slot
|
|
109
|
+
* @returns {Tag}
|
|
110
|
+
*/
|
|
111
|
+
const testFor = (tests, date, schedule, copy) => {
|
|
112
|
+
const test = tests.find((candidate) => date <= candidate.date);
|
|
113
|
+
if (test) return test;
|
|
114
|
+
const exam = { key: "final", label: copy.glossary.finalExam, order: (tests.at(-1)?.order ?? 0) + 1 };
|
|
115
|
+
return schedule.finalExam?.date ? { ...exam, date: schedule.finalExam.date, when: fullDate(schedule.finalExam.date) } : exam;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Authoring override: `::: tags` lines like `test: 2, 3` and `topic: loops`.
|
|
120
|
+
* @param {string} body
|
|
121
|
+
* @param {string} where file and slide, for errors
|
|
122
|
+
* @returns {{ test: string[], topic: string[] }}
|
|
123
|
+
*/
|
|
124
|
+
const overridesOf = (body, where) => {
|
|
125
|
+
const out = { test: [], topic: [] };
|
|
126
|
+
for (const line of block(body, "tags").split("\n").filter((l) => l.trim())) {
|
|
127
|
+
const [, kind, values] = line.match(/^\s*(\w+)\s*:\s*(.+?)\s*$/) ?? [];
|
|
128
|
+
if (!(kind in out)) throw new Error(`${where}: \`::: tags\` line "${line.trim()}" must be \`test:\` or \`topic:\``);
|
|
129
|
+
out[kind].push(...values.split(",").map((value) => value.trim()).filter(Boolean));
|
|
130
|
+
}
|
|
131
|
+
return out;
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Build the glossary from the decks: every `vocab` and `api` slide as one
|
|
136
|
+
* term, tagged by test, chapter and meeting.
|
|
137
|
+
* @param {{ lessons: object[], schedule: object, course: object, slidesDir: string }} data `slidesDir` holds the `week-N-day-M*.md` decks
|
|
138
|
+
* @returns {object | null} null when there is no deck folder
|
|
139
|
+
*/
|
|
140
|
+
export function buildGlossary({ lessons: meetings, schedule, course, slidesDir, copy = COPY_DEFAULTS }) {
|
|
141
|
+
if (!existsSync(slidesDir)) return null;
|
|
142
|
+
|
|
143
|
+
const tests = testsFrom(meetings);
|
|
144
|
+
const finalTag = testFor(tests, "9999-12-31", schedule, copy);
|
|
145
|
+
const testByNumber = new Map(tests.map((test) => [String(test.order), test]));
|
|
146
|
+
testByNumber.set("final", finalTag);
|
|
147
|
+
|
|
148
|
+
const chapterOrder = new Map();
|
|
149
|
+
const chapterTag = (title) => {
|
|
150
|
+
const number = title.match(/(\d+)/)?.[1];
|
|
151
|
+
if (!chapterOrder.has(title)) chapterOrder.set(title, number ? Number(number) : 500 + chapterOrder.size);
|
|
152
|
+
return { key: title, label: title, order: chapterOrder.get(title) };
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
const topicOrder = new Map();
|
|
156
|
+
const topicTag = (label) => {
|
|
157
|
+
const key = slug(label);
|
|
158
|
+
if (!topicOrder.has(key)) topicOrder.set(key, topicOrder.size + 1);
|
|
159
|
+
return { key, label, order: topicOrder.get(key) };
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
const decks = readdirSync(slidesDir)
|
|
163
|
+
.map((file) => ({ file, match: file.match(DECK) }))
|
|
164
|
+
.filter(({ match }) => match)
|
|
165
|
+
.map(({ file, match }) => ({ file, week: Number(match[1]), day: Number(match[2]) }))
|
|
166
|
+
.sort((a, b) => a.week - b.week || a.day - b.day || a.file.localeCompare(b.file));
|
|
167
|
+
|
|
168
|
+
/** @type {Map<string, object>} */
|
|
169
|
+
const terms = new Map();
|
|
170
|
+
const ids = new Set();
|
|
171
|
+
|
|
172
|
+
for (const deck of decks) {
|
|
173
|
+
const meeting = meetings.find((lesson) => lesson.week === deck.week && lesson.day === deck.day);
|
|
174
|
+
if (!meeting) throw new Error(`${deck.file}: week ${deck.week} day ${deck.day} is not a meeting in the lessons`);
|
|
175
|
+
const { data, content } = matter(readFileSync(join(slidesDir, deck.file), "utf8"));
|
|
176
|
+
const title = String(data.title ?? deck.file);
|
|
177
|
+
// Chapter anchors are the week's readings; meeting-level readings stand in only
|
|
178
|
+
// when the week has none (they can be dated assignments, not chapters).
|
|
179
|
+
const readings = meeting.readings.length ? meeting.readings : meeting.meetingReadings;
|
|
180
|
+
|
|
181
|
+
[...content.matchAll(/^>>> slide([^\n]*)\n([\s\S]*?)^>>>\s*$/gm)].forEach(([, info, raw], index) => {
|
|
182
|
+
const kind = /\bapi\b/.test(info) ? "api" : /\bvocab\b/.test(info) ? "vocab" : null;
|
|
183
|
+
if (!kind) return;
|
|
184
|
+
|
|
185
|
+
const where = `${deck.file} slide ${index + 1}`;
|
|
186
|
+
const body = raw.replace(/^::: notes[\s\S]*?^:::\s*$/gm, "");
|
|
187
|
+
const heading = body.match(/^# (.+)$/m)?.[1].trim();
|
|
188
|
+
if (!heading) throw new Error(`${where}: a ${kind} slide needs a "# term" heading`);
|
|
189
|
+
|
|
190
|
+
const eyebrow = block(body, "eyebrow").replace(/^- /gm, "").split("\n")[0].trim();
|
|
191
|
+
const group = eyebrow.replace(/^(?:API|Vocabulary)\s*(?:·\s*)?/, "").trim();
|
|
192
|
+
const ref = block(body, "ref").match(/\[([^\]]+)\]\(([^)]+)\)/);
|
|
193
|
+
const rest = body.replace(/^::: \w+[\s\S]*?^:::\s*$/gm, "").replace(/^# .+$/m, "").trim();
|
|
194
|
+
const key = `${plain(heading)}|${group}`.toLowerCase();
|
|
195
|
+
|
|
196
|
+
let term = terms.get(key);
|
|
197
|
+
if (!term) {
|
|
198
|
+
term = {
|
|
199
|
+
id: idFor(key, ids),
|
|
200
|
+
term: inline(heading),
|
|
201
|
+
plain: plain(heading),
|
|
202
|
+
kind,
|
|
203
|
+
group,
|
|
204
|
+
definition: inline(rest.split(/\n\s*\n/)[0]?.trim() ?? ""),
|
|
205
|
+
example: inline(block(body, "example")),
|
|
206
|
+
meta: inline(block(body, "meta")),
|
|
207
|
+
sig: inline(block(body, "sig")),
|
|
208
|
+
ref: ref ? { label: ref[1], href: ref[2] } : null,
|
|
209
|
+
tags: { test: new Map(), chapter: new Map(), meeting: new Map(), topic: new Map() },
|
|
210
|
+
taught: [],
|
|
211
|
+
};
|
|
212
|
+
terms.set(key, term);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const add = (kindOfTag, tag) => term.tags[kindOfTag].set(tag.key, tag);
|
|
216
|
+
add("test", testFor(tests, meeting.date, schedule, copy));
|
|
217
|
+
for (const reading of readings) add("chapter", chapterTag(reading.title));
|
|
218
|
+
if (!readings.length) add("chapter", noChapter(copy));
|
|
219
|
+
add("meeting", {
|
|
220
|
+
key: `w${deck.week}d${deck.day}`,
|
|
221
|
+
label: `Week ${deck.week} · ${meeting.weekday}`,
|
|
222
|
+
order: deck.week * 100 + deck.day,
|
|
223
|
+
date: meeting.date,
|
|
224
|
+
when: dateFormat(meeting.date, MONTH_DAY),
|
|
225
|
+
deck: title,
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
const overrides = overridesOf(body, where);
|
|
229
|
+
for (const number of overrides.test) {
|
|
230
|
+
if (!testByNumber.has(number)) throw new Error(`${where}: \`test: ${number}\` is not a Test n meeting in the schedule`);
|
|
231
|
+
add("test", testByNumber.get(number));
|
|
232
|
+
}
|
|
233
|
+
for (const label of overrides.topic) add("topic", topicTag(label));
|
|
234
|
+
|
|
235
|
+
term.taught.push({
|
|
236
|
+
week: deck.week,
|
|
237
|
+
day: deck.day,
|
|
238
|
+
slide: index + 1,
|
|
239
|
+
date: meeting.date,
|
|
240
|
+
weekday: meeting.weekday,
|
|
241
|
+
deck: title,
|
|
242
|
+
href: `/slides/week-${deck.week}-day-${deck.day}/#s${index + 1}`,
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const byOrder = (a, b) => a.order - b.order;
|
|
248
|
+
const keyed = [...terms.values()].map((term) => ({
|
|
249
|
+
...term,
|
|
250
|
+
key: sortKey(term.plain),
|
|
251
|
+
tags: Object.fromEntries(Object.entries(term.tags).map(([name, tags]) => [name, [...tags.values()].sort(byOrder)])),
|
|
252
|
+
}));
|
|
253
|
+
|
|
254
|
+
// The A to Z position is computed once, here; the page script only reads it.
|
|
255
|
+
const azRank = new Map([...keyed].sort(byAz).map((term, index) => [term.id, index]));
|
|
256
|
+
const first = (term) => term.taught[0];
|
|
257
|
+
/** Course order (first deck, then slide); the A to Z rank breaks ties. */
|
|
258
|
+
const list = keyed
|
|
259
|
+
.map((term) => ({ ...term, azOrder: azRank.get(term.id), azGroup: azGroupOf(term.key, copy.glossary.symbols) }))
|
|
260
|
+
.sort((a, b) => first(a).week - first(b).week || first(a).day - first(b).day || first(a).slide - first(b).slide || a.azOrder - b.azOrder);
|
|
261
|
+
|
|
262
|
+
/** Every A to Z group in order, with its terms: the no-JavaScript list. */
|
|
263
|
+
const az = [];
|
|
264
|
+
for (const term of [...list].sort((a, b) => a.azOrder - b.azOrder)) {
|
|
265
|
+
if (az.at(-1)?.key !== term.azGroup.key) az.push({ ...term.azGroup, terms: [] });
|
|
266
|
+
az.at(-1).terms.push(term);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/** Every tag in use, per kind, in display order. */
|
|
270
|
+
const tags = Object.fromEntries(
|
|
271
|
+
["test", "chapter", "meeting", "topic"].map((name) => {
|
|
272
|
+
const all = new Map(list.flatMap((term) => term.tags[name]).map((tag) => [tag.key, tag]));
|
|
273
|
+
return [name, [...all.values()].sort(byOrder)];
|
|
274
|
+
}),
|
|
275
|
+
);
|
|
276
|
+
|
|
277
|
+
/** "Chapter", "Reading", …: the noun the reading titles share, else "Reading". */
|
|
278
|
+
const noun = ["chapter", "section", "unit", "module", "lesson"].find((word) =>
|
|
279
|
+
tags.chapter.some((tag) => new RegExp(`\\b${word}\\b`, "i").test(tag.label)),
|
|
280
|
+
);
|
|
281
|
+
|
|
282
|
+
const readingLabel = noun ? copy.glossary[noun] : copy.glossary.reading;
|
|
283
|
+
|
|
284
|
+
/** For the page script: each term lists tag keys, resolved against `tags`. */
|
|
285
|
+
const payload = {
|
|
286
|
+
code: course.code,
|
|
287
|
+
readingLabel,
|
|
288
|
+
tags,
|
|
289
|
+
terms: list.map((term) => ({
|
|
290
|
+
...term,
|
|
291
|
+
tags: Object.fromEntries(Object.entries(term.tags).map(([name, all]) => [name, all.map((tag) => tag.key)])),
|
|
292
|
+
})),
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
return {
|
|
296
|
+
code: course.code,
|
|
297
|
+
readingLabel,
|
|
298
|
+
terms: list,
|
|
299
|
+
tags,
|
|
300
|
+
/** Page JSON; markup characters escaped so neither the script element nor the template engine touches it. */
|
|
301
|
+
json: JSON.stringify(payload).replace(/[<>&]/g, (char) => `\\u${char.charCodeAt(0).toString(16).padStart(4, "0")}`),
|
|
302
|
+
az,
|
|
303
|
+
};
|
|
304
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { courseDefines, readCourseData, readPackage } from "./read.js";
|
|
2
|
+
export { resolveTerm } from "./term.js";
|
|
3
|
+
export { buildGlossary } from "./glossary.js";
|
|
4
|
+
export { buildLessons, DEFAULT_DAYS, SEGMENTS } from "./lessons.js";
|
|
5
|
+
export { projectMilestones } from "./project.js";
|
|
6
|
+
export { resolveSite } from "./site.js";
|
|
7
|
+
export { isProduction, resolveAudience, resolvePdf } from "./build.js";
|
|
8
|
+
export { inlineFontFaces } from "./fonts.js";
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { resolveCopy } from "../copy.js";
|
|
2
|
+
import { projectMilestones } from "./project.js";
|
|
3
|
+
|
|
4
|
+
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
5
|
+
const utc = (iso) => new Date(`${iso}T00:00:00Z`);
|
|
6
|
+
const iso = (date) => date.toISOString().slice(0, 10);
|
|
7
|
+
const display = new Intl.DateTimeFormat("en-US", {
|
|
8
|
+
timeZone: "UTC",
|
|
9
|
+
weekday: "long",
|
|
10
|
+
month: "long",
|
|
11
|
+
day: "numeric",
|
|
12
|
+
year: "numeric",
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
/** Offset from the week's Monday, per weekday name. */
|
|
16
|
+
const WEEKDAY_OFFSETS = {
|
|
17
|
+
Monday: 0,
|
|
18
|
+
Tuesday: 1,
|
|
19
|
+
Wednesday: 2,
|
|
20
|
+
Thursday: 3,
|
|
21
|
+
Friday: 4,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const DEFAULT_DAYS = ["Tuesday", "Thursday"];
|
|
25
|
+
|
|
26
|
+
const CLOCK = /^(\d{1,2}):(\d{2})\s*(AM|PM)$/i;
|
|
27
|
+
|
|
28
|
+
const minutesOf = (time) => {
|
|
29
|
+
const match = CLOCK.exec(String(time).trim());
|
|
30
|
+
if (!match) return null;
|
|
31
|
+
const [, hour, minutes, meridiem] = match;
|
|
32
|
+
const base = (Number(hour) % 12) * 60 + Number(minutes);
|
|
33
|
+
return meridiem.toUpperCase() === "PM" ? base + 12 * 60 : base;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Class length from a meeting time: "9:00AM–9:50AM" is 50.
|
|
38
|
+
* @param {string} [range]
|
|
39
|
+
* @returns {number | null}
|
|
40
|
+
*/
|
|
41
|
+
const durationOf = (range) => {
|
|
42
|
+
const [start, end] = String(range ?? "").split(/\s*[–—-]\s*/);
|
|
43
|
+
const from = minutesOf(start);
|
|
44
|
+
const to = minutesOf(end);
|
|
45
|
+
return from != null && to != null && to > from ? to - from : null;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The lesson outline as shares of the meeting; the `absorbs` row takes the rounding.
|
|
50
|
+
* A row names its wording by copy key (`lessons.<segmentKey>`, `lessons.<openingKey>` for the first meeting);
|
|
51
|
+
* a course that passes its own `segments` can give `segment` / `opening` text instead.
|
|
52
|
+
*/
|
|
53
|
+
export const SEGMENTS = [
|
|
54
|
+
{ share: 5 / 80, segmentKey: "welcomeRecapThePrevious", openingKey: "welcomeIntroductionsHowThe" },
|
|
55
|
+
{ share: 25 / 80, segmentKey: "instructionThisWeeksTopics" },
|
|
56
|
+
{ share: 35 / 80, segmentKey: "guidedPracticeLabWork", absorbs: true },
|
|
57
|
+
{ share: 10 / 80, segmentKey: "wrapupRecapPreviewNext" },
|
|
58
|
+
{ share: 5 / 80, segmentKey: "buffer" },
|
|
59
|
+
];
|
|
60
|
+
|
|
61
|
+
const outlineFor = (minutes, firstMeeting, segments, copy) => {
|
|
62
|
+
if (!minutes) return [];
|
|
63
|
+
const words = (text, key) => text ?? copy[key];
|
|
64
|
+
const rows = segments.map((row) => ({
|
|
65
|
+
minutes: Math.max(5, Math.round((minutes * row.share) / 5) * 5),
|
|
66
|
+
segment: firstMeeting && (row.opening || row.openingKey) ? words(row.opening, row.openingKey) : words(row.segment, row.segmentKey),
|
|
67
|
+
absorbs: row.absorbs,
|
|
68
|
+
}));
|
|
69
|
+
const drift = minutes - rows.reduce((total, row) => total + row.minutes, 0);
|
|
70
|
+
const sink = rows.find((row) => row.absorbs);
|
|
71
|
+
if (sink) sink.minutes += drift;
|
|
72
|
+
return rows.map(({ minutes: length, segment }) => ({ minutes: length, segment }));
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Place each project milestone on the last class meeting on or before its due
|
|
77
|
+
* date, after any hand-authored `due[]`. A milestone with no such meeting is
|
|
78
|
+
* dropped.
|
|
79
|
+
* @param {object[]} lessons
|
|
80
|
+
* @param {object} [project] `_data/project.json`
|
|
81
|
+
* @returns {object[]} lessons, with `due` extended
|
|
82
|
+
*/
|
|
83
|
+
const withProjectDeadlines = (lessons, project) => {
|
|
84
|
+
const meetings = lessons.filter((lesson) => !lesson.noClass);
|
|
85
|
+
const milestones = projectMilestones(project);
|
|
86
|
+
return lessons.map((lesson) => {
|
|
87
|
+
const placed = milestones.filter((milestone) => meetings.findLast((meeting) => meeting.date <= milestone.due) === lesson);
|
|
88
|
+
if (!placed.length) return lesson;
|
|
89
|
+
const due = placed.map(({ title, due: date, dueTime }) => ({ title, href: project.url, due: date, dueTime }));
|
|
90
|
+
return { ...lesson, due: [...lesson.due, ...due] };
|
|
91
|
+
});
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Per-meeting lesson plans, flattened into one array for pagination.
|
|
96
|
+
* @param {{ course: object, dates: object, schedule: object, project?: object, term: { calendar: object }, segments?: typeof SEGMENTS, defaultDays?: string[] }} data
|
|
97
|
+
* @returns {object[]}
|
|
98
|
+
*/
|
|
99
|
+
export function buildLessons({ course, dates, schedule, project, term, segments = SEGMENTS, defaultDays = DEFAULT_DAYS }) {
|
|
100
|
+
if (!Array.isArray(schedule.weeks)) return [];
|
|
101
|
+
const copy = resolveCopy().lessons;
|
|
102
|
+
|
|
103
|
+
const calendar = term.calendar;
|
|
104
|
+
const termStart = utc(calendar.start);
|
|
105
|
+
const termEnd = utc(calendar.end);
|
|
106
|
+
// Monday of the week containing the term start, whatever weekday it is.
|
|
107
|
+
const weekOneMonday = new Date(termStart.getTime() - ((termStart.getUTCDay() + 6) % 7) * DAY_MS);
|
|
108
|
+
|
|
109
|
+
const holidayFor = (date) => {
|
|
110
|
+
for (const holiday of calendar.holidays) {
|
|
111
|
+
const start = typeof holiday === "string" ? holiday : holiday.start;
|
|
112
|
+
const end = typeof holiday === "string" ? holiday : holiday.end;
|
|
113
|
+
if (date >= utc(start) && date <= utc(end)) {
|
|
114
|
+
return dates.LABELS?.[start] ?? copy.collegeHoliday;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return null;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
// College-wide days that run a different weekday's class schedule.
|
|
121
|
+
const substitutionFor = (date) => calendar.substitutions?.[iso(date)] ?? null;
|
|
122
|
+
|
|
123
|
+
const meetingDays = schedule.meetings?.days ?? defaultDays;
|
|
124
|
+
const slots = meetingDays.map((weekday, index) => ({
|
|
125
|
+
day: index + 1,
|
|
126
|
+
weekday,
|
|
127
|
+
offset: WEEKDAY_OFFSETS[weekday] ?? 1,
|
|
128
|
+
}));
|
|
129
|
+
|
|
130
|
+
const lessons = [];
|
|
131
|
+
let meeting = 0;
|
|
132
|
+
schedule.weeks.forEach((week, weekIndex) => {
|
|
133
|
+
const weekNumber = weekIndex + 1;
|
|
134
|
+
const monday = new Date(weekOneMonday.getTime() + (weekNumber - 1) * 7 * DAY_MS);
|
|
135
|
+
for (const slot of slots) {
|
|
136
|
+
const date = new Date(monday.getTime() + slot.offset * DAY_MS);
|
|
137
|
+
if (date < termStart || date > termEnd) continue;
|
|
138
|
+
|
|
139
|
+
const noClass = holidayFor(date);
|
|
140
|
+
const classDaysThisWeek = lessons.filter((l) => l.week === weekNumber && !l.noClass).length;
|
|
141
|
+
// `week.days[]` entries are keyed by meeting slot (1 = first meeting of the week), not weekday.
|
|
142
|
+
const override = week.days?.find((d) => d.day === slot.day);
|
|
143
|
+
const topics = override?.topics ?? week.topics;
|
|
144
|
+
const meetingNumber = noClass ? null : meeting + 1;
|
|
145
|
+
lessons.push({
|
|
146
|
+
code: course?.code,
|
|
147
|
+
week: weekNumber,
|
|
148
|
+
day: slot.day,
|
|
149
|
+
weekday: slot.weekday,
|
|
150
|
+
date: iso(date),
|
|
151
|
+
display: display.format(date),
|
|
152
|
+
time: schedule.meetings?.time ?? copy.tbd,
|
|
153
|
+
minutes: durationOf(schedule.meetings?.time),
|
|
154
|
+
outline: outlineFor(durationOf(schedule.meetings?.time), meetingNumber === 1, segments, copy),
|
|
155
|
+
topics,
|
|
156
|
+
readings: week.readings ?? [],
|
|
157
|
+
meetingReadings: override?.readings ?? [],
|
|
158
|
+
due: override?.due ?? [],
|
|
159
|
+
resources: week.resources,
|
|
160
|
+
testWeek: topics.some((topic) => /^Test \d+$/.test(topic)),
|
|
161
|
+
noClass,
|
|
162
|
+
substitution: substitutionFor(date),
|
|
163
|
+
meeting: noClass ? null : ++meeting,
|
|
164
|
+
focus: noClass
|
|
165
|
+
? null
|
|
166
|
+
: classDaysThisWeek === 0
|
|
167
|
+
? copy.introduceThisWeeksMaterial
|
|
168
|
+
: copy.continuePracticeAndLab,
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
return withProjectDeadlines(lessons, project);
|
|
173
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The project's dated milestones, whichever way the course authors them: a
|
|
3
|
+
* `components` list (name, date) or rubric criteria that carry a `due` date.
|
|
4
|
+
* @param {object} [project] `_data/project.json`
|
|
5
|
+
* @returns {{ title: string, label: string, due: string, dueTime?: string }[]}
|
|
6
|
+
*/
|
|
7
|
+
export function projectMilestones(project) {
|
|
8
|
+
if (project?.components?.length) {
|
|
9
|
+
return project.components.map((component) => ({
|
|
10
|
+
title: `${project.title}: ${component.name}`,
|
|
11
|
+
label: component.name,
|
|
12
|
+
due: component.date,
|
|
13
|
+
dueTime: component.dueTime,
|
|
14
|
+
}));
|
|
15
|
+
}
|
|
16
|
+
return (project?.rubric?.criteria ?? [])
|
|
17
|
+
.filter((criterion) => criterion.due)
|
|
18
|
+
.map((criterion) => {
|
|
19
|
+
const title = criterion.id ? `${criterion.id} · ${criterion.title}` : criterion.title;
|
|
20
|
+
return { title, label: title, due: criterion.due, dueTime: criterion.dueTime };
|
|
21
|
+
});
|
|
22
|
+
}
|
package/lib/data/read.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @param {string} file
|
|
6
|
+
* @returns {object} the parsed JSON, or {} when the file is missing
|
|
7
|
+
*/
|
|
8
|
+
const readJson = (file) => {
|
|
9
|
+
try {
|
|
10
|
+
return JSON.parse(readFileSync(file, "utf8"));
|
|
11
|
+
} catch (error) {
|
|
12
|
+
if (error.code === "ENOENT") return {};
|
|
13
|
+
if (error instanceof SyntaxError) throw new Error(`${file} could not be read as JSON. Check for a missing or extra comma, quote or bracket. (${error.message.replace(/\s+/g, " ")})`, { cause: error });
|
|
14
|
+
throw error;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The course's authored data files.
|
|
20
|
+
* @param {string} [dataDir]
|
|
21
|
+
* @returns {{ course: object, dates: object, schedule: object, project: object, grading: object }}
|
|
22
|
+
*/
|
|
23
|
+
export function readCourseData(dataDir = "_data") {
|
|
24
|
+
return {
|
|
25
|
+
course: readJson(join(dataDir, "course.json")),
|
|
26
|
+
dates: readJson(join(dataDir, "dates.json")),
|
|
27
|
+
schedule: readJson(join(dataDir, "schedule.json")),
|
|
28
|
+
project: readJson(join(dataDir, "project.json")),
|
|
29
|
+
grading: readJson(join(dataDir, "grading.json")),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @param {string} [file]
|
|
35
|
+
* @returns {object} the course's package.json, or {} when missing
|
|
36
|
+
*/
|
|
37
|
+
export const readPackage = (file = "package.json") => readJson(file);
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Whether the course supplies its own `_data` entry of this name: a file, or a folder.
|
|
41
|
+
* @param {string} name
|
|
42
|
+
* @param {string} [dataDir]
|
|
43
|
+
* @returns {boolean}
|
|
44
|
+
*/
|
|
45
|
+
export const courseDefines = (name, dataDir = "_data") =>
|
|
46
|
+
[".js", ".cjs", ".mjs", ".json"].some((extension) => existsSync(join(dataDir, `${name}${extension}`))) || existsSync(join(dataDir, name));
|
package/lib/data/site.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
|
|
3
|
+
/** The person part of an npm `author` string: "Name <email> (url)" is "Name". */
|
|
4
|
+
const authorName = (author) =>
|
|
5
|
+
typeof author === "string" ? author.replace(/\s*[<(].*$/, "").trim() : (author?.name ?? "");
|
|
6
|
+
|
|
7
|
+
const strip = (url) => (url || "").replace(/\/+$/, "");
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The GitHub Pages address for an `owner/repo` slug. A repo named for its
|
|
11
|
+
* owner is served from the bare domain.
|
|
12
|
+
* @param {string} slug
|
|
13
|
+
* @returns {string} no trailing slash, or "" if the slug is not a pair
|
|
14
|
+
*/
|
|
15
|
+
const pagesUrl = (slug) => {
|
|
16
|
+
const [owner, repo] = (slug || "").split("/");
|
|
17
|
+
if (!owner || !repo) return "";
|
|
18
|
+
const domain = `${owner.toLowerCase()}.github.io`;
|
|
19
|
+
return repo.toLowerCase() === domain ? `https://${domain}` : `https://${domain}/${repo}`;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/** `owner/repo` from the origin remote, for a build with no CI variables. */
|
|
23
|
+
const originSlug = () => {
|
|
24
|
+
try {
|
|
25
|
+
const remote = execFileSync("git", ["remote", "get-url", "origin"], {
|
|
26
|
+
encoding: "utf8",
|
|
27
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
28
|
+
});
|
|
29
|
+
return remote.trim().replace(/\.git$/, "").split(/[:/]/).slice(-2).join("/");
|
|
30
|
+
} catch {
|
|
31
|
+
return "";
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Site-wide metadata, the global `site`. URL resolution reads the CONTEXT, URL
|
|
37
|
+
* and DEPLOY_PRIME_URL variables; see the README.
|
|
38
|
+
* @param {{ course: object, pkg?: object, institution?: { name?: string, timezone?: string, lms?: string }, site?: { description?: string, keywords?: string, language?: string }, env?: NodeJS.ProcessEnv }} data
|
|
39
|
+
* @returns {object}
|
|
40
|
+
*/
|
|
41
|
+
export function resolveSite({ course, pkg = {}, institution = {}, site = {}, env = process.env }) {
|
|
42
|
+
const isProd = env.CONTEXT === "production";
|
|
43
|
+
const prodUrl = strip(env.URL);
|
|
44
|
+
const previewUrl = strip(env.DEPLOY_PRIME_URL);
|
|
45
|
+
// No trailing slash: consumers append page.url, which starts with "/".
|
|
46
|
+
const url = isProd || !previewUrl ? prodUrl : previewUrl;
|
|
47
|
+
|
|
48
|
+
// The public address, for pages that travel and have to link back. Derived so a
|
|
49
|
+
// rename carries: the deploy's URL, then the CI repo slug, then the origin remote.
|
|
50
|
+
const hostname = prodUrl || pagesUrl(env.GITHUB_REPOSITORY) || pagesUrl(originSlug());
|
|
51
|
+
|
|
52
|
+
const name = institution.name ?? "";
|
|
53
|
+
return {
|
|
54
|
+
title: `${course.code}: ${course.name}`,
|
|
55
|
+
buildYear: new Date().getFullYear(),
|
|
56
|
+
description: site.description ?? (name ? `Course content for ${name}.` : ""),
|
|
57
|
+
language: site.language ?? "en-US",
|
|
58
|
+
author: authorName(pkg.author),
|
|
59
|
+
institution: name,
|
|
60
|
+
timezone: institution.timezone || "UTC",
|
|
61
|
+
lms: institution.lms ?? "Brightspace",
|
|
62
|
+
keywords: site.keywords ?? [name, course.code, course.name, "syllabus", "course schedule", "class resources"].filter(Boolean).join(", "),
|
|
63
|
+
url,
|
|
64
|
+
hostname,
|
|
65
|
+
preview: !isProd,
|
|
66
|
+
sitemap: "sitemap.xml",
|
|
67
|
+
robots: "robots.txt",
|
|
68
|
+
blocked: ["/.git", "/.env", "/xmlrpc.php", "/phpmyadmin", "/wp-admin", "/wp-login.php", "/wp-includes", "/wp-content"],
|
|
69
|
+
};
|
|
70
|
+
}
|