@taekwondo-db/web-app 0.0.0-stage → 0.1.2

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.
Files changed (78) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +297 -2
  3. package/assets/css/abstracts/base.css +54 -0
  4. package/assets/css/abstracts/variables.css +125 -0
  5. package/assets/css/components/breadcrumb.css +14 -0
  6. package/assets/css/components/card.css +35 -0
  7. package/assets/css/components/categories.css +200 -0
  8. package/assets/css/components/detail.css +591 -0
  9. package/assets/css/components/grade.css +79 -0
  10. package/assets/css/components/header.css +131 -0
  11. package/assets/css/components/language.css +38 -0
  12. package/assets/css/components/layout.css +151 -0
  13. package/assets/css/components/link.css +26 -0
  14. package/assets/css/components/result.css +123 -0
  15. package/assets/css/components/search.css +193 -0
  16. package/assets/css/components/tag.css +137 -0
  17. package/assets/css/style.css +17 -0
  18. package/assets/fonts/noto-serif-kr.css +28 -0
  19. package/assets/js/email.js +11 -0
  20. package/assets/js/gallery.js +30 -0
  21. package/assets/js/language.js +11 -0
  22. package/assets/js/main.js +17 -0
  23. package/assets/js/pwa.js +48 -0
  24. package/assets/js/search.js +276 -0
  25. package/assets/js/sorting.js +26 -0
  26. package/bin/taekwondo-db.js +145 -0
  27. package/content/_content.gotmpl +27 -0
  28. package/hugo.toml +32 -0
  29. package/i18n/de.json +107 -0
  30. package/i18n/en.json +107 -0
  31. package/i18n/ko.json +107 -0
  32. package/layouts/404.html +23 -0
  33. package/layouts/_partials/breadcrumb.html +11 -0
  34. package/layouts/_partials/categories.html +17 -0
  35. package/layouts/_partials/category-cards.html +36 -0
  36. package/layouts/_partials/category-group.html +7 -0
  37. package/layouts/_partials/category-section.html +15 -0
  38. package/layouts/_partials/category-tile.html +4 -0
  39. package/layouts/_partials/description.html +10 -0
  40. package/layouts/_partials/email.html +6 -0
  41. package/layouts/_partials/favicons.html +42 -0
  42. package/layouts/_partials/fonts.html +33 -0
  43. package/layouts/_partials/grade-badge.html +11 -0
  44. package/layouts/_partials/grade-name.html +14 -0
  45. package/layouts/_partials/head.html +17 -0
  46. package/layouts/_partials/header.html +38 -0
  47. package/layouts/_partials/historic.html +23 -0
  48. package/layouts/_partials/icon.html +13 -0
  49. package/layouts/_partials/language-label.html +3 -0
  50. package/layouts/_partials/language.html +13 -0
  51. package/layouts/_partials/page-title.html +13 -0
  52. package/layouts/_partials/scripts.html +25 -0
  53. package/layouts/_partials/search-form.html +11 -0
  54. package/layouts/_partials/search-index.html +40 -0
  55. package/layouts/_partials/source-entry.html +13 -0
  56. package/layouts/_partials/t.html +2 -0
  57. package/layouts/_partials/technique/photo.html +45 -0
  58. package/layouts/_partials/technique/word-meaning.html +33 -0
  59. package/layouts/_partials/technique-name.html +5 -0
  60. package/layouts/_partials/technique-row.html +17 -0
  61. package/layouts/_partials/term/list.html +24 -0
  62. package/layouts/_partials/term-name.html +4 -0
  63. package/layouts/_partials/url.html +11 -0
  64. package/layouts/_shortcodes/email.html +2 -0
  65. package/layouts/_shortcodes/operator.html +18 -0
  66. package/layouts/baseof.html +39 -0
  67. package/layouts/group/page.html +24 -0
  68. package/layouts/groups.html +48 -0
  69. package/layouts/home.html +19 -0
  70. package/layouts/page.html +17 -0
  71. package/layouts/source/page.html +67 -0
  72. package/layouts/technique/page.html +160 -0
  73. package/layouts/term/page.html +97 -0
  74. package/lib/database.js +33 -0
  75. package/lib/export.js +423 -0
  76. package/lib/service-worker.js +167 -0
  77. package/lib/validate.js +179 -0
  78. package/package.json +42 -5
@@ -0,0 +1,179 @@
1
+ /**
2
+ * Validates the data of a site — run as `taekwondo-db validate`.
3
+ *
4
+ * 1. every `$schema` pointer of the JSON files in the data directory resolves
5
+ * — a wrong path is invisible at runtime and only shows up as missing
6
+ * editor completion
7
+ * 2. the `db` options as given (own terms, sources, groups, include list,
8
+ * patches, grades) against the JSON Schemas of @taekwondo-db/database
9
+ * 3. the composed data against the same schemas — catches broken patches,
10
+ * e.g. misspelled fields
11
+ * 4. the composed data against the loader — catches dangling `$ref`s and
12
+ * unresolvable sources
13
+ * 5. site invariants: every group has a term, every technique a translation in
14
+ * every configured language but Korean
15
+ * 6. only warnings: images that are no existing file (the build leaves them
16
+ * out; the public database ships without images), and `#[...]` references
17
+ * in descriptions to what is not loaded — with `include` a builtin
18
+ * description may refer to a technique the site leaves out, which is then
19
+ * shown as plain text
20
+ */
21
+ import fs from "node:fs";
22
+ import { createRequire } from "node:module";
23
+ import path from "node:path";
24
+ import { Ajv } from "ajv";
25
+ import {
26
+ composeDatabase,
27
+ parseDescription,
28
+ TaekwondoDatabase,
29
+ } from "./database.js";
30
+
31
+ const require = createRequire(import.meta.url);
32
+ const SCHEMA_DIR = path.join(
33
+ path.dirname(require.resolve("@taekwondo-db/database/package.json")),
34
+ "db/schemas",
35
+ );
36
+
37
+ function schema(name) {
38
+ return JSON.parse(
39
+ fs.readFileSync(path.join(SCHEMA_DIR, `${name}.json`), "utf8"),
40
+ );
41
+ }
42
+
43
+ function jsonFiles(dir) {
44
+ if (!fs.existsSync(dir)) return [];
45
+ return fs
46
+ .readdirSync(dir, { recursive: true, withFileTypes: true })
47
+ .filter((entry) => entry.isFile() && entry.name.endsWith(".json"))
48
+ .map((entry) => path.join(entry.parentPath, entry.name))
49
+ .sort();
50
+ }
51
+
52
+ /**
53
+ * @param {object} options
54
+ * @param {string} options.root site directory
55
+ * @param {string} options.dataDir directory with the JSON data, relative to `root`
56
+ * @param {Record<string, any>} options.db
57
+ * @param {string[]} options.imageDirs absolute
58
+ * @param {string[]} options.languages languages of the Hugo site
59
+ * @returns {Promise<boolean>} whether everything is valid
60
+ */
61
+ export async function validateSite({
62
+ root,
63
+ dataDir,
64
+ db,
65
+ imageDirs,
66
+ languages,
67
+ }) {
68
+ let failed = false;
69
+ const ok = (message) => console.log(`✓ ${message}`);
70
+ const error = (message, details) => {
71
+ console.error(`✗ ${message}`);
72
+ if (details) console.error(details);
73
+ failed = true;
74
+ };
75
+
76
+ // 1. $schema pointers
77
+ for (const file of jsonFiles(path.resolve(root, dataDir))) {
78
+ const label = path.relative(root, file);
79
+ const { $schema } = JSON.parse(fs.readFileSync(file, "utf8"));
80
+ if (!$schema) {
81
+ error(`${label}: no $schema pointer`);
82
+ } else if (
83
+ !/^https?:/.test($schema) &&
84
+ !fs.existsSync(path.resolve(path.dirname(file), $schema))
85
+ ) {
86
+ error(`${label}: $schema does not resolve: ${$schema}`);
87
+ }
88
+ }
89
+ if (!failed) ok(`$schema pointers in ${dataDir}/ resolve`);
90
+
91
+ // 2. + 3. schemas
92
+ const ajv = new Ajv({ allErrors: true });
93
+ for (const name of fs.readdirSync(SCHEMA_DIR)) {
94
+ ajv.addSchema(schema(path.basename(name, ".json")));
95
+ }
96
+ const check = (schemaName, data, label) => {
97
+ if (data == null) return;
98
+ if (ajv.validate(`schemas/${schemaName}.json`, data)) ok(label);
99
+ else error(label, ajv.errors);
100
+ };
101
+
102
+ check("include", db.include, "db.include");
103
+ check("terms", db.terms, "db.terms");
104
+ check("sources", db.sources, "db.sources");
105
+ for (const [group, json] of Object.entries(db.techniqueGroups ?? {})) {
106
+ check("techniques", json, `db.techniqueGroups.${group}`);
107
+ }
108
+ check("techniques", db.customTechniques, "db.customTechniques");
109
+ check("patches", db.patchTechniques, "db.patchTechniques");
110
+ check("patches", db.patchTerms, "db.patchTerms");
111
+ check("grades", db.grades, "db.grades");
112
+
113
+ const composed = composeDatabase(db);
114
+ check("terms", composed.terms, "composed terms");
115
+ check("sources", composed.sources, "composed sources");
116
+ for (const [group, json] of Object.entries(composed.techniqueGroups)) {
117
+ check("techniques", json, `composed group "${group}"`);
118
+ }
119
+ check("techniques", composed.customTechniques, "composed custom techniques");
120
+
121
+ // 4. loader
122
+ let database;
123
+ try {
124
+ database = new TaekwondoDatabase({ includeBuiltins: false, ...composed });
125
+ ok("references resolve");
126
+ } catch (e) {
127
+ error(`database does not load: ${e.message}`);
128
+ return false;
129
+ }
130
+
131
+ // 5. site invariants
132
+ for (const group of database.getGroups()) {
133
+ if (!database.getTerm(group)) error(`group "${group}" has no term`);
134
+ }
135
+ for (const [name, technique] of database.getAllTechniques()) {
136
+ // Korean shows the Hangeul instead of a translation.
137
+ for (const language of languages.filter((l) => l !== "ko")) {
138
+ if (!technique.translation[language]) {
139
+ error(`${name}: missing "${language}" translation`);
140
+ }
141
+ }
142
+ for (const { src } of technique.images ?? []) {
143
+ if (!imageDirs.some((dir) => fs.existsSync(path.join(dir, src)))) {
144
+ console.warn(`! ${name}: image not found, left out: ${src}`);
145
+ }
146
+ }
147
+ }
148
+
149
+ // 6. description references
150
+ const describedEntries = [
151
+ ...database.getAllTechniques(),
152
+ ...database.getAllTerms(),
153
+ ];
154
+ for (const [name, entry] of describedEntries) {
155
+ for (const [language, text] of Object.entries(entry.description ?? {})) {
156
+ for (const segment of parseDescription(text)) {
157
+ if (segment.type !== "ref") continue;
158
+ const found =
159
+ segment.kind === "technique"
160
+ ? database.getTechnique(segment.key)
161
+ : database.getTerm(segment.key);
162
+ if (!found) {
163
+ console.warn(
164
+ `! ${name}: description.${language} refers to ${segment.kind} "${segment.key}", which is not loaded — shown as plain text`,
165
+ );
166
+ }
167
+ }
168
+ }
169
+ }
170
+
171
+ if (!failed) {
172
+ ok(
173
+ `${[...database.getAllTechniques()].length} techniques, ` +
174
+ `${[...database.getAllTerms()].length} terms, ` +
175
+ `${database.getGroups().length} groups`,
176
+ );
177
+ }
178
+ return !failed;
179
+ }
package/package.json CHANGED
@@ -1,6 +1,43 @@
1
1
  {
2
- "name": "@taekwondo-db/web-app",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
2
+ "name": "@taekwondo-db/web-app",
3
+ "version": "0.1.2",
4
+ "type": "module",
5
+ "keywords": [],
6
+ "description": "Hugo theme for the Taekwondo technique database — statically rendered, usable as a base for derived, customized sites.",
7
+ "license": "MIT",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://gitlab.com/taekwondo-db/taekwondo-db.gitlab.io.git"
11
+ },
12
+ "publishConfig": { "access": "public" },
13
+ "bin": { "taekwondo-db": "./bin/taekwondo-db.js" },
14
+ "scripts": {
15
+ "build": "cd site && node ../bin/taekwondo-db.js build",
16
+ "dev": "cd site && node ../bin/taekwondo-db.js dev",
17
+ "validate": "cd site && node ../bin/taekwondo-db.js validate",
18
+ "fix": "biome check . --write",
19
+ "lint": "biome check .",
20
+ "test": "pnpm build && playwright test",
21
+ "typecheck": "tsc -p . && tsc -p tsconfig.browser.json"
22
+ },
23
+ "dependencies": {
24
+ "@fontsource/ibm-plex-sans": "^5.3.0",
25
+ "@fontsource/noto-serif-kr": "^5.3.1",
26
+ "@taekwondo-db/database": "^0.2.2",
27
+ "ajv": "^8.20.0",
28
+ "bootstrap": "^5.3.8"
29
+ },
30
+ "engines": { "node": ">=22.15" },
31
+ "files": [
32
+ "bin",
33
+ "lib",
34
+ "hugo.toml",
35
+ "assets",
36
+ "content",
37
+ "i18n",
38
+ "layouts",
39
+ "README.md",
40
+ "LICENSE"
41
+ ],
42
+ "devDependencies": { "@types/node": "^24.19.2" }
43
+ }