@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/bundles.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
|
|
4
|
+
import { RenderPlugin } from "@11ty/eleventy";
|
|
5
|
+
|
|
6
|
+
import { assetPath } from "./assets.js";
|
|
7
|
+
|
|
8
|
+
const requireResolve = createRequire(import.meta.url).resolve;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Register 11ty bundles here for import into eleventy.config.js.
|
|
12
|
+
* @param {import('@11ty/eleventy').TemplateConfig} config
|
|
13
|
+
* @param {{ inputDir?: string }} [options]
|
|
14
|
+
*/
|
|
15
|
+
export default function registerBundles(config, { inputDir = "content" } = {}) {
|
|
16
|
+
config.addBundle("css", {
|
|
17
|
+
toFileDirectory: config.directoryAssignments.css,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
config.addBundle("js", {
|
|
21
|
+
toFileDirectory: config.directoryAssignments.js,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
let templateConfig;
|
|
25
|
+
let extensionMap;
|
|
26
|
+
config.on("eleventy.config", (instance) => {
|
|
27
|
+
templateConfig = instance;
|
|
28
|
+
});
|
|
29
|
+
config.on("eleventy.extensionmap", (map) => {
|
|
30
|
+
extensionMap = map;
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Render a template file into a page's `css` or `js` bundle, for
|
|
35
|
+
* `getBundle(type)` to inline; strips front matter and swaps `deck.css`'s
|
|
36
|
+
* font import for the inlined data URIs on an embedded render, so a deck
|
|
37
|
+
* saved to disk still has its fonts.
|
|
38
|
+
* @param {"css"|"js"} type bundle name
|
|
39
|
+
* @param {string} inputPath project-relative, e.g. "content/styles/deck.css"
|
|
40
|
+
* @param {object} data the calling page's data cascade (`$data`)
|
|
41
|
+
* @param {string} [bucket] bundle bucket; a page emits buckets in the order
|
|
42
|
+
* it needs them, which is how site CSS stays ahead of component CSS
|
|
43
|
+
* @returns {Promise<string>} always empty — the code lands in the bundle
|
|
44
|
+
*/
|
|
45
|
+
config.addJavaScriptFunction("bundleFile", async (type, inputPath, data, bucket = "default") => {
|
|
46
|
+
const options = { templateConfig, extensionMap };
|
|
47
|
+
const context = { page: data.page, eleventy: data.eleventy };
|
|
48
|
+
const located = inputPath.startsWith(`${inputDir}/`) ? assetPath(inputPath.slice(inputDir.length + 1), inputDir) : null;
|
|
49
|
+
const source = await readFile(located ?? inputPath, "utf8");
|
|
50
|
+
const body = source.replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n/, "");
|
|
51
|
+
const render =
|
|
52
|
+
body === source
|
|
53
|
+
? await RenderPlugin.File.call(context, located ?? inputPath, options)
|
|
54
|
+
: await RenderPlugin.String.call(context, body, extensionMap.getKey(inputPath), options);
|
|
55
|
+
let code = await render({ ...data, embed: true });
|
|
56
|
+
if (type === "css" && data.fontFaces) {
|
|
57
|
+
// Regex, not a literal string match: cssnano may reformat the
|
|
58
|
+
// import's quotes/whitespace in production before this runs.
|
|
59
|
+
code = code.replace(/@import\s*(?:url\()?["']?font\.css["']?\)?\s*;/, data.fontFaces);
|
|
60
|
+
}
|
|
61
|
+
return config.getPairedShortcode(type).call(context, code, bucket, data.page.url);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Add a vendored stylesheet or script to a page's bundle, verbatim.
|
|
66
|
+
* Resolved through `require.resolve`, never an assembled `node_modules`
|
|
67
|
+
* path, so it survives a linker change.
|
|
68
|
+
* @param {"css"|"js"} type bundle name
|
|
69
|
+
* @param {string} spec module specifier, e.g. "prism-themes/themes/prism-coldark-cold.css"
|
|
70
|
+
* @param {object} data the calling page's data cascade (`$data`)
|
|
71
|
+
* @param {string} [bucket] bundle bucket, as for `bundleFile`
|
|
72
|
+
* @returns {Promise<string>} always empty — the code lands in the bundle
|
|
73
|
+
*/
|
|
74
|
+
config.addJavaScriptFunction("bundleVendor", async (type, spec, data, bucket = "default") => {
|
|
75
|
+
const context = { page: data.page, eleventy: data.eleventy };
|
|
76
|
+
const code = await readFile(requireResolve(spec), "utf8");
|
|
77
|
+
return config.getPairedShortcode(type).call(context, code, bucket, data.page.url);
|
|
78
|
+
});
|
|
79
|
+
}
|
package/lib/check.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/** The options `courseKit` accepts. A group lists its own keys; `null` means a plain value. */
|
|
2
|
+
const OPTIONS = {
|
|
3
|
+
inputDir: null,
|
|
4
|
+
outputDir: null,
|
|
5
|
+
dataDir: null,
|
|
6
|
+
components: null,
|
|
7
|
+
theme: null,
|
|
8
|
+
copy: null,
|
|
9
|
+
clientCopy: null,
|
|
10
|
+
institution: ["name", "timezone", "lms"],
|
|
11
|
+
site: ["description", "keywords", "language"],
|
|
12
|
+
lessons: ["segments", "defaultDays"],
|
|
13
|
+
demos: ["runtime", "dir"],
|
|
14
|
+
slides: ["decks"],
|
|
15
|
+
pdf: ["course", "term", "dataDir"],
|
|
16
|
+
prism: ["theme", "plugins"],
|
|
17
|
+
worksheets: ["checkMode"],
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const RUNTIMES = ["none", "codepen", "pyscript"];
|
|
21
|
+
|
|
22
|
+
/** How many single-character edits turn one word into another. */
|
|
23
|
+
const distance = (a, b) => {
|
|
24
|
+
const row = Array.from({ length: b.length + 1 }, (_, index) => index);
|
|
25
|
+
for (let i = 1; i <= a.length; i++) {
|
|
26
|
+
let previous = row[0];
|
|
27
|
+
row[0] = i;
|
|
28
|
+
for (let j = 1; j <= b.length; j++) {
|
|
29
|
+
const above = row[j];
|
|
30
|
+
row[j] = Math.min(row[j] + 1, row[j - 1] + 1, previous + (a[i - 1] === b[j - 1] ? 0 : 1));
|
|
31
|
+
previous = above;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return row[b.length];
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* " Did you mean `demos`?" for a near miss, else the full list.
|
|
39
|
+
* @param {string} name
|
|
40
|
+
* @param {string[]} valid
|
|
41
|
+
* @returns {string}
|
|
42
|
+
*/
|
|
43
|
+
const hint = (name, valid) => {
|
|
44
|
+
const close = valid.find((candidate) => distance(name.toLowerCase(), candidate.toLowerCase()) <= 2);
|
|
45
|
+
return close ? ` Did you mean \`${close}\`?` : ` The options are: ${valid.join(", ")}.`;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Fail at startup, in plain language, on an option that would otherwise be
|
|
50
|
+
* ignored: a misspelled name, a runtime that does not exist, a time zone no
|
|
51
|
+
* computer knows.
|
|
52
|
+
* @param {object} [options] what the course passed to `courseKit`
|
|
53
|
+
* @throws {Error}
|
|
54
|
+
*/
|
|
55
|
+
export function checkOptions(options = {}) {
|
|
56
|
+
if (options === null || typeof options !== "object" || Array.isArray(options)) {
|
|
57
|
+
throw new Error("courseKit(config, options): options must be an object, such as { institution: { name: \"My College\" } }.");
|
|
58
|
+
}
|
|
59
|
+
for (const [name, value] of Object.entries(options)) {
|
|
60
|
+
if (!(name in OPTIONS)) throw new Error(`courseKit: unknown option \`${name}\`.${hint(name, Object.keys(OPTIONS))}`);
|
|
61
|
+
const keys = OPTIONS[name];
|
|
62
|
+
if (!keys || value === undefined || (name === "pdf" && value === false)) continue;
|
|
63
|
+
if (value === null || typeof value !== "object") throw new Error(`courseKit: \`${name}\` must be an object with ${keys.map((key) => `\`${key}\``).join(", ")}.`);
|
|
64
|
+
for (const key of Object.keys(value)) {
|
|
65
|
+
if (!keys.includes(key)) throw new Error(`courseKit: unknown option \`${name}.${key}\`.${hint(key, keys)}`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const runtime = options.demos?.runtime;
|
|
69
|
+
if (runtime !== undefined && !RUNTIMES.includes(runtime)) {
|
|
70
|
+
throw new Error(`courseKit: \`demos.runtime\` is "${runtime}", but it must be one of ${RUNTIMES.map((name) => `"${name}"`).join(", ")}.`);
|
|
71
|
+
}
|
|
72
|
+
const timeZone = options.institution?.timezone;
|
|
73
|
+
if (timeZone !== undefined) {
|
|
74
|
+
try {
|
|
75
|
+
new Intl.DateTimeFormat("en-US", { timeZone });
|
|
76
|
+
} catch {
|
|
77
|
+
throw new Error(`courseKit: \`institution.timezone\` is "${timeZone}", which is not a time zone name. Use one like "America/New_York".`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const checkMode = options.worksheets?.checkMode;
|
|
81
|
+
if (checkMode !== undefined && !["question", "end"].includes(checkMode)) {
|
|
82
|
+
throw new Error(`courseKit: \`worksheets.checkMode\` is "${checkMode}", but it must be "question" or "end".`);
|
|
83
|
+
}
|
|
84
|
+
if (options.components !== undefined && !Array.isArray(options.components)) {
|
|
85
|
+
throw new Error("courseKit: `components` must be a list of file patterns, such as [\"components/*.webc\"].");
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Problems in the course's data that do not stop the build but would give a
|
|
91
|
+
* wrong page: grade weights that do not total 100%, project pieces that do not
|
|
92
|
+
* total the project's points.
|
|
93
|
+
* @param {{ grading?: object, project?: object }} data
|
|
94
|
+
* @returns {string[]}
|
|
95
|
+
*/
|
|
96
|
+
export function courseWarnings({ grading, project } = {}) {
|
|
97
|
+
const warnings = [];
|
|
98
|
+
const weights = Object.entries(grading ?? {})
|
|
99
|
+
.filter(([key]) => key !== "$schema")
|
|
100
|
+
.map(([, category]) => parseFloat(category?.weight));
|
|
101
|
+
if (weights.length && weights.every((weight) => !Number.isNaN(weight))) {
|
|
102
|
+
const total = weights.reduce((sum, weight) => sum + weight, 0);
|
|
103
|
+
if (Math.round(total * 100) !== 10000) warnings.push(`grading.json: the weights add up to ${total}%, not 100%.`);
|
|
104
|
+
}
|
|
105
|
+
if (Array.isArray(project?.components) && typeof project.scale === "number") {
|
|
106
|
+
const points = project.components.reduce((sum, piece) => sum + (piece.points ?? 0), 0);
|
|
107
|
+
if (points !== project.scale) warnings.push(`project.json: the components add up to ${points} points, but the project's scale is ${project.scale}.`);
|
|
108
|
+
}
|
|
109
|
+
return warnings;
|
|
110
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
|
|
3
|
+
import { walk } from "./files.js";
|
|
4
|
+
import { packageRoot } from "./paths.js";
|
|
5
|
+
|
|
6
|
+
const isComponent = (name) => name.endsWith(".webc");
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Package components minus any the course repo also defines (WebC throws on a
|
|
10
|
+
* duplicate name), then the course's own.
|
|
11
|
+
* @param {string} [localDir] the course repo's component directory
|
|
12
|
+
* @returns {string[]} file paths for the WebC plugin's `components` option
|
|
13
|
+
*/
|
|
14
|
+
export function componentFiles(localDir = "_includes") {
|
|
15
|
+
const local = walk(localDir, isComponent);
|
|
16
|
+
const taken = new Set(local.map((file) => path.basename(file, ".webc")));
|
|
17
|
+
const shared = walk(path.join(packageRoot, "components"), isComponent).filter((file) => !taken.has(path.basename(file, ".webc")));
|
|
18
|
+
return [...shared, ...local];
|
|
19
|
+
}
|