@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
package/lib/filters.js
ADDED
|
@@ -0,0 +1,584 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Site-specific date filters, layered on dashly's `dateFormat`. Data files
|
|
3
|
+
* import the named functions directly; templates get them as universal
|
|
4
|
+
* filters.
|
|
5
|
+
*/
|
|
6
|
+
import { dateFormat, longDate, shortDate } from "@allons-y/dashly/filters/dates";
|
|
7
|
+
|
|
8
|
+
import { COPY_DEFAULTS } from "./copy.js";
|
|
9
|
+
import { projectMilestones } from "./data/project.js";
|
|
10
|
+
|
|
11
|
+
const FULL = { weekday: "long", month: "long", day: "numeric", year: "numeric" };
|
|
12
|
+
const MONTH_DAY = { month: "long", day: "numeric" };
|
|
13
|
+
|
|
14
|
+
/** "Monday, August 19, 2026" */
|
|
15
|
+
export const fullDate = (iso) => dateFormat(iso, FULL);
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Format an ISO date span: "October 17–20, 2026" within one month,
|
|
19
|
+
* "November 30 – December 4, 2026" with both months spelled out otherwise.
|
|
20
|
+
*/
|
|
21
|
+
export const dateRange = (start, end) =>
|
|
22
|
+
start.slice(0, 7) === end.slice(0, 7)
|
|
23
|
+
? `${dateFormat(start, MONTH_DAY)}–${Number(end.slice(8, 10))}, ${end.slice(0, 4)}`
|
|
24
|
+
: `${dateFormat(start, MONTH_DAY)} – ${dateFormat(end, MONTH_DAY)}, ${end.slice(0, 4)}`;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Display string for a course's exam slot ({ date, start, end }):
|
|
28
|
+
* "Tuesday, December 8, 2026, 9:00am–12:00pm".
|
|
29
|
+
*/
|
|
30
|
+
/**
|
|
31
|
+
* Canonical clock time: `timeOfDay("11:59 pm")` -> "11:59PM". Normalizes
|
|
32
|
+
* hand-authored times that drift into inconsistent shapes. Anything that
|
|
33
|
+
* isn't a recognizable time (or range) passes through untouched.
|
|
34
|
+
*/
|
|
35
|
+
const CLOCK = /^(\d{1,2})(?::([0-5]\d))?\s*([ap])\.?m\.?$/i;
|
|
36
|
+
|
|
37
|
+
export const timeOfDay = (value) => {
|
|
38
|
+
if (typeof value !== "string") return value;
|
|
39
|
+
const parts = value.trim().split(/\s*[–—-]\s*/);
|
|
40
|
+
if (parts.length > 2) return value;
|
|
41
|
+
const normalized = parts.map((part) => {
|
|
42
|
+
const match = CLOCK.exec(part.trim());
|
|
43
|
+
if (!match) return null;
|
|
44
|
+
const [, hour, minutes = "00", meridiem] = match;
|
|
45
|
+
return `${Number(hour)}:${minutes}${meridiem.toUpperCase()}M`;
|
|
46
|
+
});
|
|
47
|
+
return normalized.every(Boolean) ? normalized.join("–") : value;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export const examSlot = (finalExam) =>
|
|
51
|
+
finalExam
|
|
52
|
+
? `${fullDate(finalExam.date)}, ${timeOfDay(finalExam.start)}–${timeOfDay(finalExam.end)}`
|
|
53
|
+
: "";
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Display date of a section's last real class meeting (holidays skipped),
|
|
57
|
+
* from the flat lessons array (`_data/lessons.js`): the term calendar's last
|
|
58
|
+
* day of classes may itself be a holiday or otherwise unmet.
|
|
59
|
+
*/
|
|
60
|
+
export const lastMeeting = (lessons) => {
|
|
61
|
+
const meetings = (lessons ?? []).filter((lesson) => !lesson.noClass);
|
|
62
|
+
return meetings.length ? meetings[meetings.length - 1].display : "";
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const SHORT_DATE = { month: "short", day: "numeric" };
|
|
66
|
+
const DUE_DATE = { weekday: "short", month: "short", day: "numeric" };
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Due date for display: "Tue, Oct 27, 11:59PM", or without the time.
|
|
70
|
+
* @param {{due?: string, dueTime?: string}} item a reading or deadline
|
|
71
|
+
* @returns {string}
|
|
72
|
+
*/
|
|
73
|
+
export const dueLabel = (item) =>
|
|
74
|
+
item?.due ? [dateFormat(item.due, DUE_DATE), timeOfDay(item.dueTime)].filter(Boolean).join(", ") : "";
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* The kinds of deadline a chip can name, and whether each is graded. The label
|
|
78
|
+
* is the copy key `schedule.dueKind<Kind>`; nothing is ever matched on a title.
|
|
79
|
+
*/
|
|
80
|
+
export const DUE_KINDS = {
|
|
81
|
+
test: { graded: true },
|
|
82
|
+
graded: { graded: true },
|
|
83
|
+
reading: { graded: true },
|
|
84
|
+
practice: { graded: false },
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
/** @param {string} kind a key of `DUE_KINDS` */
|
|
88
|
+
const kindKey = (kind) => `dueKind${kind.charAt(0).toUpperCase()}${kind.slice(1)}`;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* The chip's word for a kind.
|
|
92
|
+
* @param {string} kind
|
|
93
|
+
* @param {typeof COPY_DEFAULTS} [copy]
|
|
94
|
+
* @returns {string}
|
|
95
|
+
*/
|
|
96
|
+
export const dueKindLabel = (kind, copy = COPY_DEFAULTS) => copy.schedule[kindKey(kind)] ?? "";
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* The key above the schedule: one entry per kind in use, in a fixed order, with its label and whether it is graded.
|
|
100
|
+
* @param {object[]} weeks `scheduleWeeks` output
|
|
101
|
+
* @param {typeof COPY_DEFAULTS} [copy]
|
|
102
|
+
* @returns {{ kind: string, label: string, graded: string }[]}
|
|
103
|
+
*/
|
|
104
|
+
export const dueKeyItems = (weeks, copy = COPY_DEFAULTS) => {
|
|
105
|
+
const present = new Set();
|
|
106
|
+
for (const { meetings = [], readings = [] } of weeks ?? []) {
|
|
107
|
+
for (const meeting of meetings) {
|
|
108
|
+
for (const item of meeting.due ?? []) present.add(item.kind);
|
|
109
|
+
for (const item of meeting.readings ?? []) if (item.due && item.kind) present.add(item.kind);
|
|
110
|
+
}
|
|
111
|
+
for (const item of readings) if (item.due && item.kind) present.add(item.kind);
|
|
112
|
+
}
|
|
113
|
+
return Object.entries(DUE_KINDS)
|
|
114
|
+
.filter(([kind]) => present.has(kind))
|
|
115
|
+
.map(([kind, { graded }]) => ({ kind, label: dueKindLabel(kind, copy), graded: graded ? copy.schedule.graded : copy.schedule.notGraded }));
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Adds the display `dueLabel` to each reading or deadline, and its `kind`:
|
|
120
|
+
* the item's own, else `fallback`. A reading with no `due` gets no kind, so no chip.
|
|
121
|
+
* @param {object[]} [items]
|
|
122
|
+
* @param {string} [fallback] the kind an item without one takes
|
|
123
|
+
* @returns {object[]}
|
|
124
|
+
*/
|
|
125
|
+
const withDueLabels = (items, fallback) =>
|
|
126
|
+
(items ?? []).map((item) => ({
|
|
127
|
+
...item,
|
|
128
|
+
dueLabel: dueLabel(item),
|
|
129
|
+
...(fallback && (fallback === "graded" || item.due) ? { kind: item.kind ?? fallback } : {}),
|
|
130
|
+
}));
|
|
131
|
+
|
|
132
|
+
const TEST_TOPIC = /^Test \d+$/;
|
|
133
|
+
|
|
134
|
+
/** The start of a meeting time, "10:00AM" from "10:00AM–11:15AM", or `undefined` when it is not a clock time. */
|
|
135
|
+
const meetingStart = (time) => {
|
|
136
|
+
const start = String(time ?? "").split(/\s*[–—-]\s*/)[0];
|
|
137
|
+
return CLOCK.test(start.trim()) ? timeOfDay(start) : undefined;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
/** "09:00" from "9:00AM" or "9AM"; `null` when it is not a clock time. */
|
|
141
|
+
const clock24 = (value) => {
|
|
142
|
+
const match = CLOCK.exec(String(value ?? "").trim());
|
|
143
|
+
if (!match) return null;
|
|
144
|
+
const [, hour, minutes = "00", meridiem] = match;
|
|
145
|
+
const base = (Number(hour) % 12) + (meridiem.toLowerCase() === "p" ? 12 : 0);
|
|
146
|
+
return `${String(base).padStart(2, "0")}:${minutes}`;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* A week's date range from its meetings, for a week header: "Aug 20",
|
|
151
|
+
* "Aug 25–27", or "Sep 29 – Oct 1".
|
|
152
|
+
* @param {{date: string}[]} meetings in calendar order
|
|
153
|
+
* @returns {string}
|
|
154
|
+
*/
|
|
155
|
+
const weekDates = (meetings) => {
|
|
156
|
+
const first = meetings[0]?.date;
|
|
157
|
+
const last = meetings.at(-1)?.date;
|
|
158
|
+
if (!first) return "";
|
|
159
|
+
const start = dateFormat(first, SHORT_DATE);
|
|
160
|
+
if (!last || last === first) return start;
|
|
161
|
+
return first.slice(0, 7) === last.slice(0, 7)
|
|
162
|
+
? `${start}–${Number(last.slice(8, 10))}`
|
|
163
|
+
: `${start} – ${dateFormat(last, SHORT_DATE)}`;
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Whether a deck is an addendum: a second deck for a meeting that already
|
|
168
|
+
* has one, marked `addendum: true` in its front matter.
|
|
169
|
+
* @param {{data: {addendum?: boolean}}} deck
|
|
170
|
+
* @returns {boolean}
|
|
171
|
+
*/
|
|
172
|
+
const isAddendum = (deck) => deck.data.addendum === true;
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* A meeting's main deck. An addendum never stands in for it, even though it
|
|
176
|
+
* shares the meeting's week and day.
|
|
177
|
+
* @param {object[]} decks `collections.deck`
|
|
178
|
+
* @param {number} week
|
|
179
|
+
* @param {number} day
|
|
180
|
+
*/
|
|
181
|
+
const mainDeck = (decks, week, day) =>
|
|
182
|
+
(decks ?? []).find((deck) => deck.data.week === week && deck.data.day === day && !isAddendum(deck));
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* A meeting's addendum deck, if it has one.
|
|
186
|
+
* @param {object[]} decks `collections.deck`
|
|
187
|
+
* @param {number} week
|
|
188
|
+
* @param {number} day
|
|
189
|
+
*/
|
|
190
|
+
const addendumFor = (decks, week, day) =>
|
|
191
|
+
(decks ?? []).find((deck) => deck.data.week === week && deck.data.day === day && isAddendum(deck));
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* The speaker-notes sheet for a meeting's deck, or for its addendum.
|
|
195
|
+
* @param {number} week
|
|
196
|
+
* @param {number} day
|
|
197
|
+
* @param {boolean} [addendum]
|
|
198
|
+
* @returns {string}
|
|
199
|
+
*/
|
|
200
|
+
export const deckNotesUrl = (week, day, addendum = false) =>
|
|
201
|
+
`/lessons/week-${week}/day-${day}/${addendum ? "addendum/" : ""}notes/`;
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* The slide index as a timetable: one row per week, one cell per meeting
|
|
205
|
+
* weekday (`schedule.meetings.days`), each cell carrying the meeting's date
|
|
206
|
+
* and its deck when one exists. A cell is `missing` when the week has no
|
|
207
|
+
* meeting on that weekday (the term's first week), `noClass` on a holiday,
|
|
208
|
+
* and `deck: null` when the meeting has no deck yet. Every deck is listed as
|
|
209
|
+
* soon as it publishes; the course no longer gates a deck behind its class
|
|
210
|
+
* meeting.
|
|
211
|
+
* @param {object[]} decks `collections.deck`
|
|
212
|
+
* @param {object[]} lessons `_data/lessons.js`
|
|
213
|
+
* @param {string[]} days `schedule.meetings.days`
|
|
214
|
+
* @returns {{days: string[], weeks: object[]}}
|
|
215
|
+
*/
|
|
216
|
+
export const slideTimetable = (decks, lessons, days = []) => {
|
|
217
|
+
const byWeek = new Map();
|
|
218
|
+
for (const lesson of lessons ?? []) {
|
|
219
|
+
if (!byWeek.has(lesson.week)) byWeek.set(lesson.week, []);
|
|
220
|
+
byWeek.get(lesson.week).push(lesson);
|
|
221
|
+
}
|
|
222
|
+
const weeks = [...byWeek].map(([week, meetings]) => ({
|
|
223
|
+
week,
|
|
224
|
+
dates: weekDates(meetings),
|
|
225
|
+
cells: days.map((weekday) => {
|
|
226
|
+
const lesson = meetings.find((meeting) => meeting.weekday === weekday);
|
|
227
|
+
if (!lesson) return { weekday, missing: true };
|
|
228
|
+
const deck = mainDeck(decks, lesson.week, lesson.day);
|
|
229
|
+
const addendum = addendumFor(decks, lesson.week, lesson.day);
|
|
230
|
+
return {
|
|
231
|
+
weekday,
|
|
232
|
+
iso: lesson.date,
|
|
233
|
+
date: dateFormat(lesson.date, SHORT_DATE),
|
|
234
|
+
noClass: lesson.noClass,
|
|
235
|
+
deck: deck
|
|
236
|
+
? {
|
|
237
|
+
title: deck.data.title,
|
|
238
|
+
url: deck.url,
|
|
239
|
+
draft: deck.data.draft === true,
|
|
240
|
+
notesUrl: deckNotesUrl(lesson.week, lesson.day),
|
|
241
|
+
}
|
|
242
|
+
: null,
|
|
243
|
+
addendum: addendum
|
|
244
|
+
? {
|
|
245
|
+
title: addendum.data.title,
|
|
246
|
+
url: addendum.url,
|
|
247
|
+
draft: addendum.data.draft === true,
|
|
248
|
+
notesUrl: deckNotesUrl(lesson.week, lesson.day, true),
|
|
249
|
+
}
|
|
250
|
+
: null,
|
|
251
|
+
};
|
|
252
|
+
}),
|
|
253
|
+
}));
|
|
254
|
+
return { days, weeks };
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* The public schedule, one group per week: the week's readings and
|
|
259
|
+
* resources beside one entry per class meeting, each carrying its weekday,
|
|
260
|
+
* short date and already-resolved topics. Sourced from `_data/lessons.js`
|
|
261
|
+
* rather than re-deriving dates from `schedule.meetings.days`, since lessons
|
|
262
|
+
* already accounts for holidays and schedule substitutions.
|
|
263
|
+
* Each meeting also carries its own deck and demo links, matched by
|
|
264
|
+
* week/day, so slides and demos never need a `resources[]` entry.
|
|
265
|
+
* @param {object[]} lessons `_data/lessons.js`
|
|
266
|
+
* @param {object[]} weeks `_data/schedule.json`'s `weeks`
|
|
267
|
+
* @param {object[]} [decks] `collections.deck`
|
|
268
|
+
* @param {object[]} [demos] `_data/demos.js`
|
|
269
|
+
* @returns {object[]}
|
|
270
|
+
*/
|
|
271
|
+
export const scheduleWeeks = (lessons, weeks, decks = [], demos = []) => {
|
|
272
|
+
const byWeek = new Map();
|
|
273
|
+
for (const lesson of lessons ?? []) {
|
|
274
|
+
if (!byWeek.has(lesson.week)) byWeek.set(lesson.week, []);
|
|
275
|
+
byWeek.get(lesson.week).push(lesson);
|
|
276
|
+
}
|
|
277
|
+
return [...byWeek].map(([week, meetings]) => {
|
|
278
|
+
const data = weeks?.[week - 1] ?? {};
|
|
279
|
+
return {
|
|
280
|
+
week,
|
|
281
|
+
dates: weekDates(meetings),
|
|
282
|
+
meetings: meetings.map((lesson) => ({
|
|
283
|
+
weekday: lesson.weekday,
|
|
284
|
+
iso: lesson.date,
|
|
285
|
+
date: dateFormat(lesson.date, SHORT_DATE),
|
|
286
|
+
display: lesson.display,
|
|
287
|
+
noClass: lesson.noClass,
|
|
288
|
+
substitution: lesson.substitution,
|
|
289
|
+
topics: lesson.topics,
|
|
290
|
+
time: lesson.time,
|
|
291
|
+
readings: withDueLabels(lesson.meetingReadings, "reading"),
|
|
292
|
+
due: [
|
|
293
|
+
...withDueLabels(lesson.due, "graded"),
|
|
294
|
+
// A test is a deadline too: one entry per "Test n" topic on a day that meets.
|
|
295
|
+
...(lesson.noClass
|
|
296
|
+
? []
|
|
297
|
+
: (lesson.topics ?? []).filter((topic) => TEST_TOPIC.test(topic)).map((topic) => {
|
|
298
|
+
const item = { title: topic, kind: "test", due: lesson.date, dueTime: meetingStart(lesson.time) };
|
|
299
|
+
return { ...item, dueLabel: dueLabel(item) };
|
|
300
|
+
})),
|
|
301
|
+
],
|
|
302
|
+
slides: mainDeck(decks, lesson.week, lesson.day)?.url,
|
|
303
|
+
addendum: addendumFor(decks, lesson.week, lesson.day)?.url,
|
|
304
|
+
demos: (demos ?? [])
|
|
305
|
+
.filter((demo) => (demo.lessons ?? []).some((at) => at.week === lesson.week && at.day === lesson.day))
|
|
306
|
+
.map((demo) => ({ title: demo.title, url: `/demo/${demo.slug}/` })),
|
|
307
|
+
})),
|
|
308
|
+
readings: withDueLabels(data.readings, "reading"),
|
|
309
|
+
resources: data.resources,
|
|
310
|
+
};
|
|
311
|
+
});
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Fill the data tokens in grading or policy prose, so a due-time phrase comes
|
|
316
|
+
* from the course's data and never from a component. `{classStart}` is the
|
|
317
|
+
* meeting days and start time, `{lastClass}` the date of the last class
|
|
318
|
+
* meeting, `{finalDue}` the final project's due date and time. A token with no
|
|
319
|
+
* data behind it is left as written.
|
|
320
|
+
* @param {string} text
|
|
321
|
+
* @param {{ schedule?: object, lessons?: object[], project?: object, copy?: typeof COPY_DEFAULTS, site?: { language?: string } }} [data] the page data (`$data`)
|
|
322
|
+
* @returns {string}
|
|
323
|
+
*/
|
|
324
|
+
export const expandTokens = (text, data = {}) => {
|
|
325
|
+
if (typeof text !== "string" || !text.includes("{")) return text;
|
|
326
|
+
const copy = data.copy ?? COPY_DEFAULTS;
|
|
327
|
+
const days = data.schedule?.meetings?.days ?? [];
|
|
328
|
+
const start = meetingStart(data.schedule?.meetings?.time);
|
|
329
|
+
const project = data.project;
|
|
330
|
+
const values = {
|
|
331
|
+
classStart: days.length
|
|
332
|
+
? copy.syllabus.classStart.replace("{days}", new Intl.ListFormat(data.site?.language ?? "en-US", { type: "conjunction" }).format(days)).replace("{time}", start ?? "").replace(/\s+at\s*$/, "")
|
|
333
|
+
: undefined,
|
|
334
|
+
lastClass: data.lessons?.length ? lastMeeting(data.lessons) || undefined : undefined,
|
|
335
|
+
finalDue: project?.due ? [fullDate(project.due), timeOfDay(project.dueTime)].filter(Boolean).join(", ") : undefined,
|
|
336
|
+
};
|
|
337
|
+
return text.replace(/\{(classStart|lastClass|finalDue)\}/g, (match, name) => values[name] ?? match);
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* Every deadline in the term, soonest first, for the home page's "Coming up":
|
|
342
|
+
* the dated items of each meeting (assignments, project milestones and tests),
|
|
343
|
+
* the dated readings, and the final exam. A reading with no `due` is not a
|
|
344
|
+
* deadline. The same item listed twice is kept once.
|
|
345
|
+
* @param {object[]} weeks `scheduleWeeks` output
|
|
346
|
+
* @param {{ finalExam?: { date: string, start?: string } }} [schedule] `_data/schedule.json`
|
|
347
|
+
* @param {typeof COPY_DEFAULTS} [copy]
|
|
348
|
+
* @returns {{ iso: string, time?: string, sort: string, title: string, href?: string, kind: string, label: string, week?: number }[]}
|
|
349
|
+
*/
|
|
350
|
+
export const courseDeadlines = (weeks, schedule, copy = COPY_DEFAULTS) => {
|
|
351
|
+
const found = [];
|
|
352
|
+
/** Sorts by the item's own clock time, else the meeting's start, else the end of the day. */
|
|
353
|
+
const add = (item, week, meetingTime, fallbackKind) => {
|
|
354
|
+
if (!item?.due) return;
|
|
355
|
+
const clock = clock24(item.dueTime) ?? clock24(meetingStart(meetingTime)) ?? "23:59";
|
|
356
|
+
found.push({
|
|
357
|
+
iso: item.due,
|
|
358
|
+
time: item.dueTime,
|
|
359
|
+
sort: `${item.due}T${clock}`,
|
|
360
|
+
title: item.title,
|
|
361
|
+
href: item.href,
|
|
362
|
+
kind: item.kind ?? fallbackKind,
|
|
363
|
+
label: item.dueLabel ?? dueLabel(item),
|
|
364
|
+
week,
|
|
365
|
+
});
|
|
366
|
+
};
|
|
367
|
+
for (const { week, meetings = [], readings = [] } of weeks ?? []) {
|
|
368
|
+
for (const meeting of meetings) {
|
|
369
|
+
for (const item of meeting.due ?? []) add(item, week, meeting.time, "graded");
|
|
370
|
+
for (const item of meeting.readings ?? []) add(item, week, meeting.time, "reading");
|
|
371
|
+
}
|
|
372
|
+
for (const item of readings) add(item, week, undefined, "reading");
|
|
373
|
+
}
|
|
374
|
+
const exam = schedule?.finalExam;
|
|
375
|
+
if (exam?.date) {
|
|
376
|
+
const item = { title: copy.schedule.finalExam, kind: "test", due: exam.date, dueTime: exam.start };
|
|
377
|
+
add({ ...item, dueLabel: dueLabel(item) }, undefined, undefined, "test");
|
|
378
|
+
}
|
|
379
|
+
const seen = new Set();
|
|
380
|
+
return found
|
|
381
|
+
.filter((item) => !seen.has(`${item.iso}|${item.title}`) && seen.add(`${item.iso}|${item.title}`))
|
|
382
|
+
.sort((a, b) => a.sort.localeCompare(b.sort) || a.title.localeCompare(b.title));
|
|
383
|
+
};
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* The schedule page's month links: one per calendar month that has a class
|
|
387
|
+
* meeting, in calendar order, pointing at the first week holding one. Dates
|
|
388
|
+
* are ISO strings, so the month is read in UTC and never shifts with the
|
|
389
|
+
* build machine's zone.
|
|
390
|
+
* @param {object[]} weeks `scheduleWeeks` output
|
|
391
|
+
* @returns {{name: string, week: number}[]}
|
|
392
|
+
*/
|
|
393
|
+
export const scheduleMonths = (weeks) => {
|
|
394
|
+
const months = new Map();
|
|
395
|
+
for (const { week, meetings } of weeks ?? []) {
|
|
396
|
+
for (const { iso } of meetings.filter((meeting) => !meeting.noClass)) {
|
|
397
|
+
const month = iso.slice(0, 7);
|
|
398
|
+
if (!months.has(month)) months.set(month, { name: dateFormat(iso, { month: "long" }), week });
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
return [...months.values()];
|
|
402
|
+
};
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* The schedule page's key dates, grouped: each test, the project's
|
|
406
|
+
* milestones, the final exam slot, and every no-class day with its reason. All
|
|
407
|
+
* of it is read from the lessons, the project and the exam slot; a group with
|
|
408
|
+
* no entries is left out. A test is a meeting whose topics hold the exact
|
|
409
|
+
* string "Test n" and that actually meets (a holiday carrying the topic is
|
|
410
|
+
* skipped).
|
|
411
|
+
* @param {object[]} lessons the `lessons` global
|
|
412
|
+
* @param {object} [project] `_data/project.json`
|
|
413
|
+
* @param {object} [finalExam] `schedule.finalExam`
|
|
414
|
+
* @param {typeof COPY_DEFAULTS} [copy] the group titles and labels
|
|
415
|
+
* @returns {{title: string, items: {label: string, date: string, note?: string}[]}[]}
|
|
416
|
+
*/
|
|
417
|
+
export const scheduleKeyDates = (lessons, project, finalExam, copy = COPY_DEFAULTS) => {
|
|
418
|
+
const words = copy.scheduleOverview;
|
|
419
|
+
const meetings = lessons ?? [];
|
|
420
|
+
const tests = meetings.flatMap((lesson) =>
|
|
421
|
+
lesson.noClass
|
|
422
|
+
? []
|
|
423
|
+
: lesson.topics.filter((topic) => /^Test \d+$/.test(topic)).map((topic) => ({ label: topic, date: lesson.display })),
|
|
424
|
+
);
|
|
425
|
+
const stages = projectMilestones(project).map((milestone) => ({
|
|
426
|
+
label: milestone.label,
|
|
427
|
+
date: [fullDate(milestone.due), timeOfDay(milestone.dueTime)].filter(Boolean).join(", "),
|
|
428
|
+
}));
|
|
429
|
+
const groups = [
|
|
430
|
+
{ title: words.tests, items: tests },
|
|
431
|
+
{ title: project?.title ?? words.finalProject, items: stages },
|
|
432
|
+
{ title: words.finalExam, items: finalExam ? [{ label: words.exam, date: examSlot(finalExam), note: finalExam.note }] : [] },
|
|
433
|
+
{
|
|
434
|
+
title: words.noClass,
|
|
435
|
+
items: meetings.filter((lesson) => lesson.noClass).map((lesson) => ({ label: lesson.noClass, date: lesson.display })),
|
|
436
|
+
},
|
|
437
|
+
];
|
|
438
|
+
return groups.filter((group) => group.items.length);
|
|
439
|
+
};
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* The demo listing in the schedule's shape: one group per week that has a
|
|
443
|
+
* demo, one entry per class meeting inside it, each meeting carrying its
|
|
444
|
+
* deck link and the demos shown that day. A demo reused in a later class is
|
|
445
|
+
* listed under every meeting it ran in, so the listing matches the schedule
|
|
446
|
+
* meeting for meeting: in full the first time (`alsoOn` naming the later
|
|
447
|
+
* dates), and as a one-line pointer after that (`firstShown`). Weeks and meetings with
|
|
448
|
+
* no demo are left out; a lesson ref matching no meeting is dropped.
|
|
449
|
+
* @param {object[]} demos `_data/demos.js`
|
|
450
|
+
* @param {object[]} lessons `_data/lessons.js`
|
|
451
|
+
* @param {object[]} [decks] `collections.deck`
|
|
452
|
+
* @returns {object[]}
|
|
453
|
+
*/
|
|
454
|
+
export const demoWeeks = (demos, lessons, decks = []) => {
|
|
455
|
+
const byWeek = new Map();
|
|
456
|
+
for (const lesson of lessons ?? []) {
|
|
457
|
+
if (!byWeek.has(lesson.week)) byWeek.set(lesson.week, []);
|
|
458
|
+
byWeek.get(lesson.week).push(lesson);
|
|
459
|
+
}
|
|
460
|
+
const dateOf = (ref) => {
|
|
461
|
+
const lesson = (lessons ?? []).find((item) => item.week === ref.week && item.day === ref.day);
|
|
462
|
+
return lesson ? dateFormat(lesson.date, SHORT_DATE) : "";
|
|
463
|
+
};
|
|
464
|
+
return [...byWeek]
|
|
465
|
+
.map(([week, meetings]) => ({
|
|
466
|
+
week,
|
|
467
|
+
dates: weekDates(meetings),
|
|
468
|
+
meetings: meetings
|
|
469
|
+
.map((lesson) => ({
|
|
470
|
+
week: lesson.week,
|
|
471
|
+
day: lesson.day,
|
|
472
|
+
weekday: lesson.weekday,
|
|
473
|
+
iso: lesson.date,
|
|
474
|
+
date: dateFormat(lesson.date, SHORT_DATE),
|
|
475
|
+
slides: mainDeck(decks, lesson.week, lesson.day)?.url,
|
|
476
|
+
addendum: addendumFor(decks, lesson.week, lesson.day)?.url,
|
|
477
|
+
demos: (demos ?? [])
|
|
478
|
+
.filter((demo) => (demo.lessons ?? []).some((at) => at.week === lesson.week && at.day === lesson.day))
|
|
479
|
+
.map((demo) => ({
|
|
480
|
+
title: demo.title,
|
|
481
|
+
description: demo.description,
|
|
482
|
+
url: `/demo/${demo.slug}/`,
|
|
483
|
+
download: demo.download,
|
|
484
|
+
firstShown: (demo.lessons ?? [])
|
|
485
|
+
.filter((at) => at.week < lesson.week || (at.week === lesson.week && at.day < lesson.day))
|
|
486
|
+
.map(dateOf)
|
|
487
|
+
.find(Boolean),
|
|
488
|
+
alsoOn: (demo.lessons ?? [])
|
|
489
|
+
.filter((at) => at.week > lesson.week || (at.week === lesson.week && at.day > lesson.day))
|
|
490
|
+
.map(dateOf)
|
|
491
|
+
.filter(Boolean),
|
|
492
|
+
})),
|
|
493
|
+
}))
|
|
494
|
+
.filter((meeting) => meeting.demos.length),
|
|
495
|
+
}))
|
|
496
|
+
.filter((week) => week.meetings.length);
|
|
497
|
+
};
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* The deck(s) tied to one class meeting (its main deck, then any addendum),
|
|
501
|
+
* for the instructor lesson-plan page. No availability gating here — the whole directory is
|
|
502
|
+
* instructor-only already.
|
|
503
|
+
* @param {object[]} decks `collections.deck`
|
|
504
|
+
* @param {number} week
|
|
505
|
+
* @param {number} day
|
|
506
|
+
*/
|
|
507
|
+
export const decksFor = (decks, week, day) =>
|
|
508
|
+
(decks ?? [])
|
|
509
|
+
.filter((deck) => deck.data.week === week && deck.data.day === day)
|
|
510
|
+
.map((deck) => ({
|
|
511
|
+
title: deck.data.title,
|
|
512
|
+
url: deck.url,
|
|
513
|
+
addendum: isAddendum(deck),
|
|
514
|
+
notesUrl: deckNotesUrl(week, day, isAddendum(deck)),
|
|
515
|
+
}));
|
|
516
|
+
|
|
517
|
+
/**
|
|
518
|
+
* The exercises to announce at one meeting: each is listed on the last class
|
|
519
|
+
* meeting on or before its `due` date, so a deadline on a non-meeting day
|
|
520
|
+
* still appears.
|
|
521
|
+
* @param {Array<{url: string, data: {title: string, due?: string, dueTime?: string}}>} assignments
|
|
522
|
+
* @param {{week: number, day: number}} lesson the meeting being rendered
|
|
523
|
+
* @param {Array<{week: number, day: number, date: string, noClass?: string}>} lessons every meeting, in order
|
|
524
|
+
* @returns {Array<{title: string, url: string, due: string, dueTime?: string, dueLabel: string}>}
|
|
525
|
+
*/
|
|
526
|
+
export const assignmentsDue = (assignments, lesson, lessons) =>
|
|
527
|
+
(assignments ?? [])
|
|
528
|
+
.filter(({ data }) => {
|
|
529
|
+
if (!data.due) return false;
|
|
530
|
+
const announce = (lessons ?? []).findLast((l) => !l.noClass && l.date <= data.due);
|
|
531
|
+
return announce?.week === lesson?.week && announce?.day === lesson?.day;
|
|
532
|
+
})
|
|
533
|
+
.map(({ data, url }) => ({
|
|
534
|
+
title: data.title,
|
|
535
|
+
url,
|
|
536
|
+
due: data.due,
|
|
537
|
+
dueTime: data.dueTime,
|
|
538
|
+
dueLabel: dueLabel({ due: data.due, dueTime: data.dueTime }),
|
|
539
|
+
}));
|
|
540
|
+
|
|
541
|
+
/**
|
|
542
|
+
* The `data-prefill` payload for a CodePen prefill embed, as an attribute-safe
|
|
543
|
+
* JSON string. The apostrophe escaping is load-bearing: the payload sits in a
|
|
544
|
+
* single-quoted attribute.
|
|
545
|
+
* @param {{title?: string, description?: string, tags?: string[]}} options
|
|
546
|
+
* @returns {string}
|
|
547
|
+
*/
|
|
548
|
+
export const codepenPrefill = ({ title = "", description = "", tags = [] } = {}) =>
|
|
549
|
+
JSON.stringify({ title, description, tags, stylesheets: [], scripts: [] }).replace(/'/g, "\\u0027");
|
|
550
|
+
|
|
551
|
+
/**
|
|
552
|
+
* An email address as base64, so it never appears in the served markup; the
|
|
553
|
+
* page's script decodes it for the reader. An address already encoded (it has
|
|
554
|
+
* no "@") passes through, so a course that encodes it itself still works.
|
|
555
|
+
* @param {string} [email]
|
|
556
|
+
* @returns {string}
|
|
557
|
+
*/
|
|
558
|
+
export const encodeEmail = (email) => (typeof email === "string" && email.includes("@") ? Buffer.from(email).toString("base64") : (email ?? ""));
|
|
559
|
+
|
|
560
|
+
/** @param {import('@11ty/eleventy').TemplateConfig} config */
|
|
561
|
+
export default function registerFilters(config) {
|
|
562
|
+
config.addFilter("fullDate", fullDate);
|
|
563
|
+
config.addFilter("dateRange", dateRange);
|
|
564
|
+
config.addFilter("examSlot", examSlot);
|
|
565
|
+
config.addFilter("timeOfDay", timeOfDay);
|
|
566
|
+
config.addFilter("lastMeeting", lastMeeting);
|
|
567
|
+
config.addFilter("slideTimetable", slideTimetable);
|
|
568
|
+
config.addFilter("scheduleWeeks", scheduleWeeks);
|
|
569
|
+
config.addFilter("scheduleMonths", scheduleMonths);
|
|
570
|
+
config.addFilter("courseDeadlines", courseDeadlines);
|
|
571
|
+
config.addFilter("expandTokens", expandTokens);
|
|
572
|
+
config.addFilter("dueKindLabel", dueKindLabel);
|
|
573
|
+
config.addFilter("dueKeyItems", dueKeyItems);
|
|
574
|
+
config.addFilter("scheduleKeyDates", scheduleKeyDates);
|
|
575
|
+
config.addFilter("demoWeeks", demoWeeks);
|
|
576
|
+
config.addFilter("decksFor", decksFor);
|
|
577
|
+
config.addFilter("deckNotesUrl", deckNotesUrl);
|
|
578
|
+
config.addFilter("assignmentsDue", assignmentsDue);
|
|
579
|
+
config.addFilter("dueLabel", dueLabel);
|
|
580
|
+
config.addFilter("encodeEmail", encodeEmail);
|
|
581
|
+
config.addFilter("longDate", longDate);
|
|
582
|
+
config.addFilter("shortDate", shortDate);
|
|
583
|
+
config.addFilter("codepenPrefill", codepenPrefill);
|
|
584
|
+
}
|
package/lib/fit.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Slide fit check — reports each deck slide whose content leaves the slide
|
|
3
|
+
* box. CHECK_FIT=1 warns, CHECK_FIT=strict fails the build; unset skips it
|
|
4
|
+
* (Puppeteer is imported lazily, so no Chromium launch). See "Building" in
|
|
5
|
+
* docs/configuration.md.
|
|
6
|
+
*/
|
|
7
|
+
import { resolve } from "node:path";
|
|
8
|
+
|
|
9
|
+
import { servePublic } from "./pdf.js";
|
|
10
|
+
|
|
11
|
+
/** Projector size the decks are authored against. */
|
|
12
|
+
export const VIEWPORT = { width: 1280, height: 720 };
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Whether a build result is a deck page: `<decksDir>/*.md`, never the index.
|
|
16
|
+
* @param {string} decksDir
|
|
17
|
+
* @returns {(result: { inputPath: string }) => boolean}
|
|
18
|
+
*/
|
|
19
|
+
const deckMatcher = (decksDir) => {
|
|
20
|
+
const escaped = decksDir.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
21
|
+
const pattern = new RegExp(`^\\./${escaped}/[^/]+\\.md$`);
|
|
22
|
+
return (result) => pattern.test(result.inputPath);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Runs inside the page. Bounds are relative to the top of each slide's 16:9
|
|
27
|
+
* box, so anything outside 0..box height spills.
|
|
28
|
+
*/
|
|
29
|
+
/* global document */
|
|
30
|
+
const measureSlides = () =>
|
|
31
|
+
[...document.querySelectorAll(".slide")].map((slide) => {
|
|
32
|
+
const box = slide.querySelector(".slide-body").getBoundingClientRect();
|
|
33
|
+
let min = Infinity;
|
|
34
|
+
let max = -Infinity;
|
|
35
|
+
for (const element of slide.querySelectorAll(".slide-body *")) {
|
|
36
|
+
const rect = element.getBoundingClientRect();
|
|
37
|
+
if (!rect.height) continue;
|
|
38
|
+
min = Math.min(min, rect.top - box.top);
|
|
39
|
+
max = Math.max(max, rect.bottom - box.top);
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
id: slide.id,
|
|
43
|
+
heading: slide.querySelector("h1, h2")?.textContent.trim() ?? "",
|
|
44
|
+
above: Math.max(0, Math.round(-min)),
|
|
45
|
+
below: Math.max(0, Math.round(max - box.height)),
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Register the `eleventy.after` handler that measures every deck.
|
|
51
|
+
* @param {import('@11ty/eleventy').TemplateConfig} config
|
|
52
|
+
* @param {{ outputDir?: string, decksDir?: string }} [options]
|
|
53
|
+
*/
|
|
54
|
+
export default function registerSlideFitCheck(config, { outputDir = "public", decksDir = "content/slides" } = {}) {
|
|
55
|
+
const isDeck = deckMatcher(decksDir);
|
|
56
|
+
config.on("eleventy.after", async ({ runMode, results }) => {
|
|
57
|
+
const mode = process.env.CHECK_FIT;
|
|
58
|
+
if (runMode !== "build" || !mode) return;
|
|
59
|
+
const decks = (results ?? []).filter(isDeck);
|
|
60
|
+
if (!decks.length) return;
|
|
61
|
+
|
|
62
|
+
const root = resolve(outputDir);
|
|
63
|
+
const pathPrefix = config.pathPrefix ?? "/";
|
|
64
|
+
const { default: puppeteer } = await import("puppeteer");
|
|
65
|
+
|
|
66
|
+
const server = servePublic(root, pathPrefix);
|
|
67
|
+
await new Promise((done) => server.listen(0, "127.0.0.1", done));
|
|
68
|
+
const { port } = server.address();
|
|
69
|
+
const browser = await puppeteer.launch({
|
|
70
|
+
args: process.env.CI ? ["--no-sandbox", "--disable-setuid-sandbox"] : [],
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
const failures = [];
|
|
74
|
+
let total = 0;
|
|
75
|
+
try {
|
|
76
|
+
const page = await browser.newPage();
|
|
77
|
+
await page.setViewport(VIEWPORT);
|
|
78
|
+
// Nothing mid-transition when the measurement runs.
|
|
79
|
+
await page.emulateMediaFeatures([
|
|
80
|
+
{ name: "prefers-reduced-motion", value: "reduce" },
|
|
81
|
+
{ name: "prefers-color-scheme", value: "light" },
|
|
82
|
+
]);
|
|
83
|
+
for (const deck of decks) {
|
|
84
|
+
await page.goto(`http://127.0.0.1:${port}${pathPrefix.replace(/\/$/, "")}${deck.url}`, { waitUntil: "load" });
|
|
85
|
+
await page.evaluateHandle("document.fonts.ready");
|
|
86
|
+
const slides = await page.evaluate(measureSlides);
|
|
87
|
+
total += slides.length;
|
|
88
|
+
for (const slide of slides) {
|
|
89
|
+
if (!slide.above && !slide.below) continue;
|
|
90
|
+
const where = [slide.above && `${slide.above}px over the top`, slide.below && `${slide.below}px over the bottom`].filter(Boolean).join(", ");
|
|
91
|
+
failures.push(`${deck.inputPath.replace(/^\.\//, "")} #${slide.id} “${slide.heading}”: ${where}`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
await page.close();
|
|
95
|
+
} finally {
|
|
96
|
+
await browser.close();
|
|
97
|
+
server.close();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const size = `${VIEWPORT.width}×${VIEWPORT.height}`;
|
|
101
|
+
for (const failure of failures) process.stderr.write(`[slide-fit] ${failure}\n`);
|
|
102
|
+
const summary = `[slide-fit] ${failures.length} of ${total} slides overflow at ${size}`;
|
|
103
|
+
if (failures.length && mode === "strict") throw new Error(`${summary} — set CHECK_FIT=1 to warn instead`);
|
|
104
|
+
process.stdout.write(`${summary}${failures.length ? " (CHECK_FIT=strict fails the build)" : ""}\n`);
|
|
105
|
+
});
|
|
106
|
+
}
|