@mark1russell7/site-pages 0.5.3 → 0.6.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/README.md +3 -4
- package/build/config/site-config.d.ts +114 -0
- package/build/config/site-config.d.ts.map +1 -0
- package/build/config/site-config.js +211 -0
- package/build/config/site-config.js.map +1 -0
- package/build/demo.d.ts +4 -13
- package/build/demo.d.ts.map +1 -1
- package/build/demo.js +1 -48
- package/build/demo.js.map +1 -1
- package/package.json +6 -1
package/README.md
CHANGED
|
@@ -558,9 +558,7 @@ A home page shows the package at work: a visitor types or clicks, and the page s
|
|
|
558
558
|
| `examples(row, items, pick)` | Fills a row with one button for each example `[label, value]`. A click starts `pick` with the value. |
|
|
559
559
|
| `verdict(pass, title, ...reason)` | Makes the line of a verdict: a check or a cross, a title in bold and a reason. The mark has the label "Pass" or "Fail". |
|
|
560
560
|
| `setField(field, value)` | Sets the value of a field and sends an `input` event, as typing does. |
|
|
561
|
-
| `
|
|
562
|
-
| `partsOf(text, find)` | Divides a text into parts at each copy of `find`. |
|
|
563
|
-
| `markedText(parts, label)` | Shows a text in a box, with a `mark` element on each part with `hit`. |
|
|
561
|
+
| `markedText(parts, label)` | Shows a text in a box, with a `mark` element on each part with `hit`. `partsAt` and `partsOf` of `@mark1russell7/text/parts` give the parts. |
|
|
564
562
|
|
|
565
563
|
The style gives these classes:
|
|
566
564
|
|
|
@@ -576,7 +574,8 @@ The style gives these classes:
|
|
|
576
574
|
```ts
|
|
577
575
|
import "@mark1russell7/site-pages/demo.css";
|
|
578
576
|
import { byId } from "@mark1russell7/site-pages/chrome";
|
|
579
|
-
import { examples, markedText,
|
|
577
|
+
import { examples, markedText, setField, verdict } from "@mark1russell7/site-pages/demo";
|
|
578
|
+
import { partsOf } from "@mark1russell7/text/parts";
|
|
580
579
|
|
|
581
580
|
const input = byId<HTMLInputElement>("find");
|
|
582
581
|
const result = byId("result");
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The site config of a repository: the one home of the inputs of its site build (CI.md, "The site config").
|
|
3
|
+
*
|
|
4
|
+
* The file `.github/site.json` of the repository holds them. `reusable-pages.yml` (build and deploy) and
|
|
5
|
+
* `reusable-pages-check.yml` (the check of a pull request) read it with `main.ts` of this folder. Thus the two
|
|
6
|
+
* workflows build the same site, and each value has one home. The rules of `@mark1russell7/conventions` read it too.
|
|
7
|
+
*
|
|
8
|
+
* A repository with no file gives the old inputs of `reusable-pages.yml`, and the resolver takes them. Thus an old
|
|
9
|
+
* caller keeps its site. A repository that has the file and also gives a site input gets an error.
|
|
10
|
+
*
|
|
11
|
+
* In each string value, `{owner}` is the owner of the repository and `{repo}` is its name. This file imports nothing,
|
|
12
|
+
* so the workflow starts it from the template commit with no install.
|
|
13
|
+
*/
|
|
14
|
+
/** The path of the site config in a repository. */
|
|
15
|
+
export declare const SITE_CONFIG_PATH = ".github/site.json";
|
|
16
|
+
/** The type of a key: a string, a boolean or a map of environment variables. */
|
|
17
|
+
export type SiteConfigKind = "string" | "boolean" | "env";
|
|
18
|
+
/** The site config: a value for each key. CI.md tells each key. */
|
|
19
|
+
export interface SiteConfig {
|
|
20
|
+
/** The command that builds the site. It is the one necessary key, with `out`. */
|
|
21
|
+
readonly build: string;
|
|
22
|
+
/** The folder of the built site. */
|
|
23
|
+
readonly out: string;
|
|
24
|
+
/** The environment variables of the build. `{owner}` and `{repo}` change in each value. */
|
|
25
|
+
readonly env: Readonly<Record<string, string>>;
|
|
26
|
+
/** `true` gives the build the token of the job as `GITHUB_TOKEN`. */
|
|
27
|
+
readonly "github-token": boolean;
|
|
28
|
+
/** The Node.js version of the build. */
|
|
29
|
+
readonly "node-version": string;
|
|
30
|
+
/** A file with the Node.js version, for example `.nvmrc`. It replaces `node-version`. */
|
|
31
|
+
readonly "node-version-file": string;
|
|
32
|
+
/** `true` adds the Releases page and the Status page. */
|
|
33
|
+
readonly "site-pages": boolean;
|
|
34
|
+
/** The npm version of site-pages for its pages. Empty uses the template commit. */
|
|
35
|
+
readonly "site-pages-version": string;
|
|
36
|
+
/** The roadmap file of the Status page, for example `docs/ROADMAP.md`. */
|
|
37
|
+
readonly roadmap: string;
|
|
38
|
+
/** The base path of the site, for example `/{repo}/`. */
|
|
39
|
+
readonly base: string;
|
|
40
|
+
/** The npm packages of the Releases page, with commas between them. */
|
|
41
|
+
readonly packages: string;
|
|
42
|
+
/** The folder of the changesets of the Status page. */
|
|
43
|
+
readonly changesets: string;
|
|
44
|
+
/** The group of the pages of the site. */
|
|
45
|
+
readonly group: string;
|
|
46
|
+
/** A style file of the site for the pages of site-pages. */
|
|
47
|
+
readonly css: string;
|
|
48
|
+
/** The name of the site in the bar and in the titles. */
|
|
49
|
+
readonly "site-name": string;
|
|
50
|
+
/** `true` writes only the data files of the pages, with no HTML. */
|
|
51
|
+
readonly "data-only": boolean;
|
|
52
|
+
/** A file of data stamps, for the freshness gate. */
|
|
53
|
+
readonly "data-stamps": string;
|
|
54
|
+
/** `true` checks the pages in a browser at each width. */
|
|
55
|
+
readonly "site-check": boolean;
|
|
56
|
+
/** The pages of the site check, with commas between them. */
|
|
57
|
+
readonly "site-check-pages": string;
|
|
58
|
+
/** The widths of the site check, with commas between them. */
|
|
59
|
+
readonly "site-check-widths": string;
|
|
60
|
+
/** A probe script of the site check. */
|
|
61
|
+
readonly "site-check-probe": string;
|
|
62
|
+
/** The Playwright version of the site check. */
|
|
63
|
+
readonly "site-check-playwright": string;
|
|
64
|
+
/** `true` gives each page the bar of the site. */
|
|
65
|
+
readonly "site-bar": boolean;
|
|
66
|
+
/** The pages of the bar, with commas between them. */
|
|
67
|
+
readonly "site-bar-pages": string;
|
|
68
|
+
/** The npm name of the package of the site, for the npm link of the bar. */
|
|
69
|
+
readonly "site-bar-npm": string;
|
|
70
|
+
/** `true` gives each code block the scroll cue. */
|
|
71
|
+
readonly "scroll-cue": boolean;
|
|
72
|
+
/** A key of IndexNow. After each deploy that is not scheduled, the URLs go to the engines. */
|
|
73
|
+
readonly "indexnow-key": string;
|
|
74
|
+
}
|
|
75
|
+
/** A key of the site config. */
|
|
76
|
+
export type SiteConfigKey = keyof SiteConfig;
|
|
77
|
+
/** The type and the default of one key. The defaults are those of the inputs of `reusable-pages.yml`. */
|
|
78
|
+
export interface SiteConfigKeySpec<T> {
|
|
79
|
+
readonly kind: SiteConfigKind;
|
|
80
|
+
readonly default: T;
|
|
81
|
+
}
|
|
82
|
+
/** The keys of the site config, with their types and their defaults. */
|
|
83
|
+
export declare const SITE_CONFIG_KEYS: { readonly [K in SiteConfigKey]: SiteConfigKeySpec<SiteConfig[K]>; };
|
|
84
|
+
/** The input of {@link resolveSiteConfig}. */
|
|
85
|
+
export interface SiteConfigInput {
|
|
86
|
+
/** The text of .github/site.json, or undefined when the repository has no such file. */
|
|
87
|
+
readonly file: string | undefined;
|
|
88
|
+
/** The path of the file, for the messages. */
|
|
89
|
+
readonly path: string;
|
|
90
|
+
/** The inputs of the workflow (toJSON(inputs)), or undefined when the workflow has no old inputs. */
|
|
91
|
+
readonly inputs: Readonly<Record<string, unknown>> | undefined;
|
|
92
|
+
/** The repository, "owner/name". */
|
|
93
|
+
readonly repository: string;
|
|
94
|
+
}
|
|
95
|
+
/** The site config and its source, or an error. */
|
|
96
|
+
export type SiteConfigResult = {
|
|
97
|
+
readonly config: SiteConfig;
|
|
98
|
+
readonly source: "file" | "inputs";
|
|
99
|
+
} | {
|
|
100
|
+
readonly error: string;
|
|
101
|
+
};
|
|
102
|
+
/** This function puts the owner and the name of the repository in for {owner} and {repo}. */
|
|
103
|
+
export declare function fillRepository(value: string, repository: string): string;
|
|
104
|
+
/**
|
|
105
|
+
* This function gives the keys of the site config that the inputs of a workflow give with a value other than the default.
|
|
106
|
+
* The input `env` of `reusable-pages.yml` is a JSON string, and `"{}"` or an empty string is its default.
|
|
107
|
+
*/
|
|
108
|
+
export declare function inputsGiven(inputs: Readonly<Record<string, unknown>>): SiteConfigKey[];
|
|
109
|
+
/**
|
|
110
|
+
* This function gives the site config of a repository from its file, or from the old inputs when it has no file. The
|
|
111
|
+
* workflow uses only the file. Thus a repository with the file gets an error for a site input that is not its default.
|
|
112
|
+
*/
|
|
113
|
+
export declare function resolveSiteConfig(input: SiteConfigInput): SiteConfigResult;
|
|
114
|
+
//# sourceMappingURL=site-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"site-config.d.ts","names":[],"sources":["../../src/config/site-config.ts"],"mappings":";;;;;;;;;;;;;;qBAea;;YAGD;;iBAGK;;WAEN;;WAEA;;WAEA,KAAK,SAAS;;WAEd;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;;YAIC,sBAAsB;;iBAGjB,kBAAkB;WACxB,MAAM;WACN,SAAS;;;qBAIP,8BAA8B,KAAK,gBAAgB,kBAAkB,WAAW;;iBA+B5E;;WAEN;;WAEA;;WAEA,QAAQ,SAAS;;WAEjB;;;YAIC;WAA8B,QAAQ;WAAqB;;WAAyC;;;wBAKhG,eAAe,eAAe;;;;;wBA4B9B,YAAY,QAAQ,SAAS,2BAA2B;;;;;wBAaxD,kBAAkB,OAAO,kBAAkB"}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
// src/config/site-config.ts
|
|
2
|
+
/**
|
|
3
|
+
* The site config of a repository: the one home of the inputs of its site build (CI.md, "The site config").
|
|
4
|
+
*
|
|
5
|
+
* The file `.github/site.json` of the repository holds them. `reusable-pages.yml` (build and deploy) and
|
|
6
|
+
* `reusable-pages-check.yml` (the check of a pull request) read it with `main.ts` of this folder. Thus the two
|
|
7
|
+
* workflows build the same site, and each value has one home. The rules of `@mark1russell7/conventions` read it too.
|
|
8
|
+
*
|
|
9
|
+
* A repository with no file gives the old inputs of `reusable-pages.yml`, and the resolver takes them. Thus an old
|
|
10
|
+
* caller keeps its site. A repository that has the file and also gives a site input gets an error.
|
|
11
|
+
*
|
|
12
|
+
* In each string value, `{owner}` is the owner of the repository and `{repo}` is its name. This file imports nothing,
|
|
13
|
+
* so the workflow starts it from the template commit with no install.
|
|
14
|
+
*/
|
|
15
|
+
/** The path of the site config in a repository. */
|
|
16
|
+
const SITE_CONFIG_PATH = ".github/site.json";
|
|
17
|
+
/** The keys of the site config, with their types and their defaults. */
|
|
18
|
+
const SITE_CONFIG_KEYS = {
|
|
19
|
+
build: {
|
|
20
|
+
kind: "string",
|
|
21
|
+
default: ""
|
|
22
|
+
},
|
|
23
|
+
out: {
|
|
24
|
+
kind: "string",
|
|
25
|
+
default: ""
|
|
26
|
+
},
|
|
27
|
+
env: {
|
|
28
|
+
kind: "env",
|
|
29
|
+
default: {}
|
|
30
|
+
},
|
|
31
|
+
"github-token": {
|
|
32
|
+
kind: "boolean",
|
|
33
|
+
default: false
|
|
34
|
+
},
|
|
35
|
+
"node-version": {
|
|
36
|
+
kind: "string",
|
|
37
|
+
default: "26"
|
|
38
|
+
},
|
|
39
|
+
"node-version-file": {
|
|
40
|
+
kind: "string",
|
|
41
|
+
default: ""
|
|
42
|
+
},
|
|
43
|
+
"site-pages": {
|
|
44
|
+
kind: "boolean",
|
|
45
|
+
default: true
|
|
46
|
+
},
|
|
47
|
+
"site-pages-version": {
|
|
48
|
+
kind: "string",
|
|
49
|
+
default: ""
|
|
50
|
+
},
|
|
51
|
+
roadmap: {
|
|
52
|
+
kind: "string",
|
|
53
|
+
default: ""
|
|
54
|
+
},
|
|
55
|
+
base: {
|
|
56
|
+
kind: "string",
|
|
57
|
+
default: ""
|
|
58
|
+
},
|
|
59
|
+
packages: {
|
|
60
|
+
kind: "string",
|
|
61
|
+
default: ""
|
|
62
|
+
},
|
|
63
|
+
changesets: {
|
|
64
|
+
kind: "string",
|
|
65
|
+
default: ""
|
|
66
|
+
},
|
|
67
|
+
group: {
|
|
68
|
+
kind: "string",
|
|
69
|
+
default: ""
|
|
70
|
+
},
|
|
71
|
+
css: {
|
|
72
|
+
kind: "string",
|
|
73
|
+
default: ""
|
|
74
|
+
},
|
|
75
|
+
"site-name": {
|
|
76
|
+
kind: "string",
|
|
77
|
+
default: ""
|
|
78
|
+
},
|
|
79
|
+
"data-only": {
|
|
80
|
+
kind: "boolean",
|
|
81
|
+
default: false
|
|
82
|
+
},
|
|
83
|
+
"data-stamps": {
|
|
84
|
+
kind: "string",
|
|
85
|
+
default: ""
|
|
86
|
+
},
|
|
87
|
+
"site-check": {
|
|
88
|
+
kind: "boolean",
|
|
89
|
+
default: false
|
|
90
|
+
},
|
|
91
|
+
"site-check-pages": {
|
|
92
|
+
kind: "string",
|
|
93
|
+
default: ""
|
|
94
|
+
},
|
|
95
|
+
"site-check-widths": {
|
|
96
|
+
kind: "string",
|
|
97
|
+
default: ""
|
|
98
|
+
},
|
|
99
|
+
"site-check-probe": {
|
|
100
|
+
kind: "string",
|
|
101
|
+
default: ""
|
|
102
|
+
},
|
|
103
|
+
"site-check-playwright": {
|
|
104
|
+
kind: "string",
|
|
105
|
+
default: "1.64.1"
|
|
106
|
+
},
|
|
107
|
+
"site-bar": {
|
|
108
|
+
kind: "boolean",
|
|
109
|
+
default: false
|
|
110
|
+
},
|
|
111
|
+
"site-bar-pages": {
|
|
112
|
+
kind: "string",
|
|
113
|
+
default: ""
|
|
114
|
+
},
|
|
115
|
+
"site-bar-npm": {
|
|
116
|
+
kind: "string",
|
|
117
|
+
default: ""
|
|
118
|
+
},
|
|
119
|
+
"scroll-cue": {
|
|
120
|
+
kind: "boolean",
|
|
121
|
+
default: true
|
|
122
|
+
},
|
|
123
|
+
"indexnow-key": {
|
|
124
|
+
kind: "string",
|
|
125
|
+
default: ""
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
const NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
129
|
+
/** This function puts the owner and the name of the repository in for {owner} and {repo}. */
|
|
130
|
+
function fillRepository(value, repository) {
|
|
131
|
+
const [owner = "", repo = ""] = repository.split("/");
|
|
132
|
+
return value.replaceAll("{owner}", owner).replaceAll("{repo}", repo);
|
|
133
|
+
}
|
|
134
|
+
/** This function checks one value against the type of its key, and gives the value or an error. */
|
|
135
|
+
function check(key, value, where, repository) {
|
|
136
|
+
const kind = SITE_CONFIG_KEYS[key].kind;
|
|
137
|
+
if (kind === "boolean") return typeof value === "boolean" ? { value } : { error: `${where}: "${key}" must be true or false.` };
|
|
138
|
+
if (kind === "string") return typeof value === "string" ? { value: fillRepository(value, repository) } : { error: `${where}: "${key}" must be a string.` };
|
|
139
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) return { error: `${where}: "env" must be an object of strings.` };
|
|
140
|
+
const env = {};
|
|
141
|
+
for (const [name, text] of Object.entries(value)) {
|
|
142
|
+
if (!NAME.test(name)) return { error: `${where}: "${name}" of "env" is not a name of an environment variable.` };
|
|
143
|
+
if (typeof text !== "string") return { error: `${where}: the value of "${name}" of "env" must be a string.` };
|
|
144
|
+
env[name] = fillRepository(text, repository);
|
|
145
|
+
}
|
|
146
|
+
return { value: env };
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* This function gives the keys of the site config that the inputs of a workflow give with a value other than the default.
|
|
150
|
+
* The input `env` of `reusable-pages.yml` is a JSON string, and `"{}"` or an empty string is its default.
|
|
151
|
+
*/
|
|
152
|
+
function inputsGiven(inputs) {
|
|
153
|
+
return Object.keys(SITE_CONFIG_KEYS).filter((key) => {
|
|
154
|
+
const value = inputs[key];
|
|
155
|
+
if (value === void 0) return false;
|
|
156
|
+
if (key === "env") return !(value === "" || typeof value === "string" && value.replace(/\s/g, "") === "{}");
|
|
157
|
+
return value !== SITE_CONFIG_KEYS[key].default;
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* This function gives the site config of a repository from its file, or from the old inputs when it has no file. The
|
|
162
|
+
* workflow uses only the file. Thus a repository with the file gets an error for a site input that is not its default.
|
|
163
|
+
*/
|
|
164
|
+
function resolveSiteConfig(input) {
|
|
165
|
+
const config = Object.fromEntries(Object.entries(SITE_CONFIG_KEYS).map(([key, spec]) => [key, spec.default]));
|
|
166
|
+
let source;
|
|
167
|
+
if (input.file !== void 0) {
|
|
168
|
+
const given = input.inputs === void 0 ? [] : inputsGiven(input.inputs);
|
|
169
|
+
if (given.length > 0) return { error: `The repository has ${input.path} and the workflow also gives the inputs ${given.join(", ")}. Give the site values only in ${input.path}.` };
|
|
170
|
+
let data;
|
|
171
|
+
try {
|
|
172
|
+
data = JSON.parse(input.file);
|
|
173
|
+
} catch (error) {
|
|
174
|
+
return { error: `${input.path} is not JSON: ${error.message}` };
|
|
175
|
+
}
|
|
176
|
+
if (data === null || typeof data !== "object" || Array.isArray(data)) return { error: `${input.path} must be a JSON object.` };
|
|
177
|
+
for (const [key, value] of Object.entries(data)) {
|
|
178
|
+
if (key === "$schema" || key === "$comment") continue;
|
|
179
|
+
if (!Object.hasOwn(SITE_CONFIG_KEYS, key)) return { error: `${input.path}: "${key}" is not a key of the site config. CI.md tells the keys.` };
|
|
180
|
+
const checked = check(key, value, input.path, input.repository);
|
|
181
|
+
if ("error" in checked) return checked;
|
|
182
|
+
config[key] = checked.value;
|
|
183
|
+
}
|
|
184
|
+
source = "file";
|
|
185
|
+
} else if (input.inputs !== void 0) {
|
|
186
|
+
for (const key of Object.keys(SITE_CONFIG_KEYS)) {
|
|
187
|
+
let value = input.inputs[key];
|
|
188
|
+
if (value === void 0) continue;
|
|
189
|
+
if (key === "env") {
|
|
190
|
+
if (value === "") continue;
|
|
191
|
+
try {
|
|
192
|
+
value = JSON.parse(String(value));
|
|
193
|
+
} catch (error) {
|
|
194
|
+
return { error: `The input env is not JSON: ${error.message}` };
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
const checked = check(key, value, "the inputs", input.repository);
|
|
198
|
+
if ("error" in checked) return checked;
|
|
199
|
+
config[key] = checked.value;
|
|
200
|
+
}
|
|
201
|
+
source = "inputs";
|
|
202
|
+
} else return { error: `The repository has no ${input.path}. The check of the site needs the file (CI.md, "The site config").` };
|
|
203
|
+
for (const key of ["build", "out"]) if (config[key] === "") return { error: `${source === "file" ? input.path : "the inputs of the workflow"} gives no "${key}". The site config needs "build" and "out".` };
|
|
204
|
+
return {
|
|
205
|
+
config,
|
|
206
|
+
source
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
export { SITE_CONFIG_KEYS, SITE_CONFIG_PATH, fillRepository, inputsGiven, resolveSiteConfig };
|
|
210
|
+
|
|
211
|
+
//# sourceMappingURL=site-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"site-config.js","names":[],"sources":["../../src/config/site-config.ts"],"sourcesContent":["/**\n * The site config of a repository: the one home of the inputs of its site build (CI.md, \"The site config\").\n *\n * The file `.github/site.json` of the repository holds them. `reusable-pages.yml` (build and deploy) and\n * `reusable-pages-check.yml` (the check of a pull request) read it with `main.ts` of this folder. Thus the two\n * workflows build the same site, and each value has one home. The rules of `@mark1russell7/conventions` read it too.\n *\n * A repository with no file gives the old inputs of `reusable-pages.yml`, and the resolver takes them. Thus an old\n * caller keeps its site. A repository that has the file and also gives a site input gets an error.\n *\n * In each string value, `{owner}` is the owner of the repository and `{repo}` is its name. This file imports nothing,\n * so the workflow starts it from the template commit with no install.\n */\n\n/** The path of the site config in a repository. */\nexport const SITE_CONFIG_PATH = \".github/site.json\";\n\n/** The type of a key: a string, a boolean or a map of environment variables. */\nexport type SiteConfigKind = \"string\" | \"boolean\" | \"env\";\n\n/** The site config: a value for each key. CI.md tells each key. */\nexport interface SiteConfig {\n /** The command that builds the site. It is the one necessary key, with `out`. */\n readonly build: string;\n /** The folder of the built site. */\n readonly out: string;\n /** The environment variables of the build. `{owner}` and `{repo}` change in each value. */\n readonly env: Readonly<Record<string, string>>;\n /** `true` gives the build the token of the job as `GITHUB_TOKEN`. */\n readonly \"github-token\": boolean;\n /** The Node.js version of the build. */\n readonly \"node-version\": string;\n /** A file with the Node.js version, for example `.nvmrc`. It replaces `node-version`. */\n readonly \"node-version-file\": string;\n /** `true` adds the Releases page and the Status page. */\n readonly \"site-pages\": boolean;\n /** The npm version of site-pages for its pages. Empty uses the template commit. */\n readonly \"site-pages-version\": string;\n /** The roadmap file of the Status page, for example `docs/ROADMAP.md`. */\n readonly roadmap: string;\n /** The base path of the site, for example `/{repo}/`. */\n readonly base: string;\n /** The npm packages of the Releases page, with commas between them. */\n readonly packages: string;\n /** The folder of the changesets of the Status page. */\n readonly changesets: string;\n /** The group of the pages of the site. */\n readonly group: string;\n /** A style file of the site for the pages of site-pages. */\n readonly css: string;\n /** The name of the site in the bar and in the titles. */\n readonly \"site-name\": string;\n /** `true` writes only the data files of the pages, with no HTML. */\n readonly \"data-only\": boolean;\n /** A file of data stamps, for the freshness gate. */\n readonly \"data-stamps\": string;\n /** `true` checks the pages in a browser at each width. */\n readonly \"site-check\": boolean;\n /** The pages of the site check, with commas between them. */\n readonly \"site-check-pages\": string;\n /** The widths of the site check, with commas between them. */\n readonly \"site-check-widths\": string;\n /** A probe script of the site check. */\n readonly \"site-check-probe\": string;\n /** The Playwright version of the site check. */\n readonly \"site-check-playwright\": string;\n /** `true` gives each page the bar of the site. */\n readonly \"site-bar\": boolean;\n /** The pages of the bar, with commas between them. */\n readonly \"site-bar-pages\": string;\n /** The npm name of the package of the site, for the npm link of the bar. */\n readonly \"site-bar-npm\": string;\n /** `true` gives each code block the scroll cue. */\n readonly \"scroll-cue\": boolean;\n /** A key of IndexNow. After each deploy that is not scheduled, the URLs go to the engines. */\n readonly \"indexnow-key\": string;\n}\n\n/** A key of the site config. */\nexport type SiteConfigKey = keyof SiteConfig;\n\n/** The type and the default of one key. The defaults are those of the inputs of `reusable-pages.yml`. */\nexport interface SiteConfigKeySpec<T> {\n readonly kind: SiteConfigKind;\n readonly default: T;\n}\n\n/** The keys of the site config, with their types and their defaults. */\nexport const SITE_CONFIG_KEYS: { readonly [K in SiteConfigKey]: SiteConfigKeySpec<SiteConfig[K]> } = {\n build: { kind: \"string\", default: \"\" },\n out: { kind: \"string\", default: \"\" },\n env: { kind: \"env\", default: {} },\n \"github-token\": { kind: \"boolean\", default: false },\n \"node-version\": { kind: \"string\", default: \"26\" },\n \"node-version-file\": { kind: \"string\", default: \"\" },\n \"site-pages\": { kind: \"boolean\", default: true },\n \"site-pages-version\": { kind: \"string\", default: \"\" },\n roadmap: { kind: \"string\", default: \"\" },\n base: { kind: \"string\", default: \"\" },\n packages: { kind: \"string\", default: \"\" },\n changesets: { kind: \"string\", default: \"\" },\n group: { kind: \"string\", default: \"\" },\n css: { kind: \"string\", default: \"\" },\n \"site-name\": { kind: \"string\", default: \"\" },\n \"data-only\": { kind: \"boolean\", default: false },\n \"data-stamps\": { kind: \"string\", default: \"\" },\n \"site-check\": { kind: \"boolean\", default: false },\n \"site-check-pages\": { kind: \"string\", default: \"\" },\n \"site-check-widths\": { kind: \"string\", default: \"\" },\n \"site-check-probe\": { kind: \"string\", default: \"\" },\n \"site-check-playwright\": { kind: \"string\", default: \"1.64.1\" },\n \"site-bar\": { kind: \"boolean\", default: false },\n \"site-bar-pages\": { kind: \"string\", default: \"\" },\n \"site-bar-npm\": { kind: \"string\", default: \"\" },\n \"scroll-cue\": { kind: \"boolean\", default: true },\n \"indexnow-key\": { kind: \"string\", default: \"\" },\n};\n\n/** The input of {@link resolveSiteConfig}. */\nexport interface SiteConfigInput {\n /** The text of .github/site.json, or undefined when the repository has no such file. */\n readonly file: string | undefined;\n /** The path of the file, for the messages. */\n readonly path: string;\n /** The inputs of the workflow (toJSON(inputs)), or undefined when the workflow has no old inputs. */\n readonly inputs: Readonly<Record<string, unknown>> | undefined;\n /** The repository, \"owner/name\". */\n readonly repository: string;\n}\n\n/** The site config and its source, or an error. */\nexport type SiteConfigResult = { readonly config: SiteConfig; readonly source: \"file\" | \"inputs\" } | { readonly error: string };\n\nconst NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;\n\n/** This function puts the owner and the name of the repository in for {owner} and {repo}. */\nexport function fillRepository(value: string, repository: string): string {\n const [owner = \"\", repo = \"\"] = repository.split(\"/\");\n return value.replaceAll(\"{owner}\", owner).replaceAll(\"{repo}\", repo);\n}\n\n/** This function checks one value against the type of its key, and gives the value or an error. */\nfunction check(key: SiteConfigKey, value: unknown, where: string, repository: string): { value: SiteConfig[SiteConfigKey] } | { error: string } {\n const kind: SiteConfigKind = SITE_CONFIG_KEYS[key].kind;\n if (kind === \"boolean\") {\n return typeof value === \"boolean\" ? { value } : { error: `${where}: \"${key}\" must be true or false.` };\n }\n if (kind === \"string\") {\n return typeof value === \"string\" ? { value: fillRepository(value, repository) } : { error: `${where}: \"${key}\" must be a string.` };\n }\n if (value === null || typeof value !== \"object\" || Array.isArray(value)) return { error: `${where}: \"env\" must be an object of strings.` };\n const env: Record<string, string> = {};\n for (const [name, text] of Object.entries(value)) {\n if (!NAME.test(name)) return { error: `${where}: \"${name}\" of \"env\" is not a name of an environment variable.` };\n if (typeof text !== \"string\") return { error: `${where}: the value of \"${name}\" of \"env\" must be a string.` };\n env[name] = fillRepository(text, repository);\n }\n return { value: env };\n}\n\n/**\n * This function gives the keys of the site config that the inputs of a workflow give with a value other than the default.\n * The input `env` of `reusable-pages.yml` is a JSON string, and `\"{}\"` or an empty string is its default.\n */\nexport function inputsGiven(inputs: Readonly<Record<string, unknown>>): SiteConfigKey[] {\n return (Object.keys(SITE_CONFIG_KEYS) as SiteConfigKey[]).filter((key) => {\n const value = inputs[key];\n if (value === undefined) return false;\n if (key === \"env\") return !(value === \"\" || (typeof value === \"string\" && value.replace(/\\s/g, \"\") === \"{}\"));\n return value !== SITE_CONFIG_KEYS[key].default;\n });\n}\n\n/**\n * This function gives the site config of a repository from its file, or from the old inputs when it has no file. The\n * workflow uses only the file. Thus a repository with the file gets an error for a site input that is not its default.\n */\nexport function resolveSiteConfig(input: SiteConfigInput): SiteConfigResult {\n const config = Object.fromEntries(Object.entries(SITE_CONFIG_KEYS).map(([key, spec]) => [key, spec.default])) as Record<SiteConfigKey, unknown>;\n let source: \"file\" | \"inputs\";\n if (input.file !== undefined) {\n const given = input.inputs === undefined ? [] : inputsGiven(input.inputs);\n if (given.length > 0) {\n return { error: `The repository has ${input.path} and the workflow also gives the inputs ${given.join(\", \")}. Give the site values only in ${input.path}.` };\n }\n let data: unknown;\n try {\n data = JSON.parse(input.file);\n } catch (error) {\n return { error: `${input.path} is not JSON: ${(error as Error).message}` };\n }\n if (data === null || typeof data !== \"object\" || Array.isArray(data)) return { error: `${input.path} must be a JSON object.` };\n for (const [key, value] of Object.entries(data)) {\n if (key === \"$schema\" || key === \"$comment\") continue;\n if (!Object.hasOwn(SITE_CONFIG_KEYS, key)) return { error: `${input.path}: \"${key}\" is not a key of the site config. CI.md tells the keys.` };\n const checked = check(key as SiteConfigKey, value, input.path, input.repository);\n if (\"error\" in checked) return checked;\n config[key as SiteConfigKey] = checked.value;\n }\n source = \"file\";\n } else if (input.inputs !== undefined) {\n for (const key of Object.keys(SITE_CONFIG_KEYS) as SiteConfigKey[]) {\n let value = input.inputs[key];\n if (value === undefined) continue;\n // The input env of reusable-pages.yml is a JSON string, and an empty string means no variables.\n if (key === \"env\") {\n if (value === \"\") continue;\n try {\n value = JSON.parse(String(value));\n } catch (error) {\n return { error: `The input env is not JSON: ${(error as Error).message}` };\n }\n }\n const checked = check(key, value, \"the inputs\", input.repository);\n if (\"error\" in checked) return checked;\n config[key] = checked.value;\n }\n source = \"inputs\";\n } else {\n return { error: `The repository has no ${input.path}. The check of the site needs the file (CI.md, \"The site config\").` };\n }\n for (const key of [\"build\", \"out\"] as const) {\n if (config[key] === \"\") {\n const home = source === \"file\" ? input.path : \"the inputs of the workflow\";\n return { error: `${home} gives no \"${key}\". The site config needs \"build\" and \"out\".` };\n }\n }\n return { config: config as SiteConfig, source };\n}\n"],"mappings":";;;;;;;;;;;;;;;AAeA,MAAa,mBAAmB;;AAyEhC,MAAa,mBAAwF;CACnG,OAAO;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AAQ,KAAK,MAAM,OAAO,KAAK,CAAC;IAClC,SAAS,OAAO;KACd,OAAO,EAAE,OAAO,8BAA+B,MAAgB,UAAU;IAC3E;GACF;GACA,MAAM,UAAU,MAAM,KAAK,OAAO,cAAc,MAAM,UAAU;GAChE,IAAI,WAAW,SAAS,OAAO;GAC/B,OAAO,OAAO,QAAQ;EACxB;EACA,SAAS;CACX,OACE,OAAO,EAAE,OAAO,yBAAyB,MAAM,KAAK,oEAAoE;CAE1H,KAAK,MAAM,OAAO,CAAC,SAAS,KAAK,GAC/B,IAAI,OAAO,SAAS,IAElB,OAAO,EAAE,OAAO,GADH,WAAW,SAAS,MAAM,OAAO,6BACtB,aAAa,IAAI,6CAA6C;CAG1F,OAAO;EAAU;EAAsB;CAAO;AAChD"}
|
package/build/demo.d.ts
CHANGED
|
@@ -25,23 +25,14 @@ export declare function verdict(pass: boolean, title: Child, ...reason: readonly
|
|
|
25
25
|
* Thus an example button changes a field, and the demo of the field shows the new value.
|
|
26
26
|
*/
|
|
27
27
|
export declare function setField(field: HTMLInputElement | HTMLTextAreaElement, value: string): void;
|
|
28
|
-
/**
|
|
28
|
+
/**
|
|
29
|
+
* A part of a text. `markedText` puts a `mark` element on a part with `hit`. The functions `partsAt` and `partsOf` of
|
|
30
|
+
* `@mark1russell7/text/parts` give the parts of a text.
|
|
31
|
+
*/
|
|
29
32
|
export interface TextPart {
|
|
30
33
|
readonly text: string;
|
|
31
34
|
readonly hit: boolean;
|
|
32
35
|
}
|
|
33
|
-
/**
|
|
34
|
-
* This function divides a text into parts at ranges of code units, `[start, end)`. Each range gives a
|
|
35
|
-
* part with `hit`, and the text between the ranges gives parts with no `hit`. The function sorts the
|
|
36
|
-
* ranges, joins the ranges that overlap, and clamps each range to the text. Two ranges that touch stay
|
|
37
|
-
* two parts. An empty range gives no part.
|
|
38
|
-
*/
|
|
39
|
-
export declare function partsAt(text: string, ranges: readonly (readonly [start: number, end: number])[]): TextPart[];
|
|
40
|
-
/**
|
|
41
|
-
* This function divides a text into parts at each copy of `find`, from the start, with no overlap.
|
|
42
|
-
* Each copy gives a part with `hit`. An empty `find` gives one part with no `hit`.
|
|
43
|
-
*/
|
|
44
|
-
export declare function partsOf(text: string, find: string): TextPart[];
|
|
45
36
|
/**
|
|
46
37
|
* This function shows a text in a `pre` box, with a `mark` element on each part with `hit`. The box is
|
|
47
38
|
* a group with the label, so a screen reader names it. A text with no parts shows "(empty)".
|
package/build/demo.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"demo.d.ts","names":[],"sources":["../src/demo.ts"],"mappings":";;;;;;;;;YAUY,oBAAoB,eAAe;;;;;;wBAO/B,SAAS,KAAK,aAAa,gBAAgB,WAAW,OAAO,yBAAyB;;;;;;wBAetF,QAAQ,eAAe,OAAO,UAAU,iBAAiB,UAAU;;;;;wBAanE,SAAS,OAAO,mBAAmB,qBAAqB
|
|
1
|
+
{"version":3,"file":"demo.d.ts","names":[],"sources":["../src/demo.ts"],"mappings":";;;;;;;;;YAUY,oBAAoB,eAAe;;;;;;wBAO/B,SAAS,KAAK,aAAa,gBAAgB,WAAW,OAAO,yBAAyB;;;;;;wBAetF,QAAQ,eAAe,OAAO,UAAU,iBAAiB,UAAU;;;;;wBAanE,SAAS,OAAO,mBAAmB,qBAAqB;;;;;iBASvD;WACN;WACA;;;;;;wBAOK,WAAW,gBAAgB,YAAY,gBAAgB"}
|
package/build/demo.js
CHANGED
|
@@ -46,53 +46,6 @@ function setField(field, value) {
|
|
|
46
46
|
field.dispatchEvent(new Event("input", { bubbles: true }));
|
|
47
47
|
}
|
|
48
48
|
/**
|
|
49
|
-
* This function divides a text into parts at ranges of code units, `[start, end)`. Each range gives a
|
|
50
|
-
* part with `hit`, and the text between the ranges gives parts with no `hit`. The function sorts the
|
|
51
|
-
* ranges, joins the ranges that overlap, and clamps each range to the text. Two ranges that touch stay
|
|
52
|
-
* two parts. An empty range gives no part.
|
|
53
|
-
*/
|
|
54
|
-
function partsAt(text, ranges) {
|
|
55
|
-
const clamp = (n) => Math.min(Math.max(Math.trunc(n), 0), text.length);
|
|
56
|
-
const sorted = ranges.map(([start, end]) => [clamp(start), clamp(end)]).filter(([start, end]) => end > start).sort((a, b) => a[0] - b[0]);
|
|
57
|
-
const parts = [];
|
|
58
|
-
let at = 0;
|
|
59
|
-
for (const [start, end] of sorted) {
|
|
60
|
-
if (end <= at) continue;
|
|
61
|
-
if (start < at) {
|
|
62
|
-
const last = parts[parts.length - 1];
|
|
63
|
-
parts[parts.length - 1] = {
|
|
64
|
-
text: last.text + text.slice(at, end),
|
|
65
|
-
hit: true
|
|
66
|
-
};
|
|
67
|
-
} else {
|
|
68
|
-
if (start > at) parts.push({
|
|
69
|
-
text: text.slice(at, start),
|
|
70
|
-
hit: false
|
|
71
|
-
});
|
|
72
|
-
parts.push({
|
|
73
|
-
text: text.slice(start, end),
|
|
74
|
-
hit: true
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
at = end;
|
|
78
|
-
}
|
|
79
|
-
if (at < text.length) parts.push({
|
|
80
|
-
text: text.slice(at),
|
|
81
|
-
hit: false
|
|
82
|
-
});
|
|
83
|
-
return parts;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* This function divides a text into parts at each copy of `find`, from the start, with no overlap.
|
|
87
|
-
* Each copy gives a part with `hit`. An empty `find` gives one part with no `hit`.
|
|
88
|
-
*/
|
|
89
|
-
function partsOf(text, find) {
|
|
90
|
-
if (find === "") return partsAt(text, []);
|
|
91
|
-
const ranges = [];
|
|
92
|
-
for (let at = text.indexOf(find); at >= 0; at = text.indexOf(find, at + find.length)) ranges.push([at, at + find.length]);
|
|
93
|
-
return partsAt(text, ranges);
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
49
|
* This function shows a text in a `pre` box, with a `mark` element on each part with `hit`. The box is
|
|
97
50
|
* a group with the label, so a screen reader names it. A text with no parts shows "(empty)".
|
|
98
51
|
*/
|
|
@@ -104,6 +57,6 @@ function markedText(parts, label) {
|
|
|
104
57
|
"aria-label": label
|
|
105
58
|
}, nodes.length > 0 ? nodes : h("span", { class: "sp-empty" }, "(empty)"));
|
|
106
59
|
}
|
|
107
|
-
export { examples, markedText,
|
|
60
|
+
export { examples, markedText, setField, verdict };
|
|
108
61
|
|
|
109
62
|
//# sourceMappingURL=demo.js.map
|
package/build/demo.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"demo.js","names":[],"sources":["../src/demo.ts"],"sourcesContent":["/**\n * The parts of a live demo on a page. The parts are a row of example buttons, the line of a verdict,\n * a field that a script fills and a text with marks. This module imports no Node.js module, so a site\n * can bundle it. Its style is in `@mark1russell7/site-pages/demo.css`.\n *\n * @packageDocumentation\n */\nimport { h, type Child } from \"./chrome.ts\";\n\n/** An example of a demo: the label of its button and the value that a click gives. */\nexport type Example = readonly [label: string, value: string];\n\n/**\n * This function fills a row with one button for each example, and gives the buttons. A click on a\n * button starts `pick` with the value of its example. When the value is not the label, the `title` of\n * the button is the value, so a pointer shows the full value.\n */\nexport function examples(row: HTMLElement, items: readonly Example[], pick: (value: string) => void): HTMLButtonElement[] {\n const buttons = items.map(([label, value]) => {\n const button = h(\"button\", { type: \"button\", class: \"sp-example\", title: value === label ? undefined : value }, label);\n button.addEventListener(\"click\", () => pick(value));\n return button;\n });\n row.replaceChildren(...buttons);\n return buttons;\n}\n\n/**\n * This function makes the line of a verdict: a mark, a title in bold and a reason. The mark is a check\n * for a pass and a cross for a fail. Its label tells the same to a screen reader, so the color is not\n * the only cue. The title has no punctuation of its own: give \"Correct:\" for a colon.\n */\nexport function verdict(pass: boolean, title: Child, ...reason: readonly Child[]): HTMLDivElement {\n return h(\n \"div\",\n { class: pass ? \"sp-verdict sp-pass\" : \"sp-verdict sp-fail\" },\n h(\"span\", { class: \"sp-mark\", role: \"img\", \"aria-label\": pass ? \"Pass\" : \"Fail\" }, pass ? \"✓\" : \"✕\"),\n h(\"div\", {}, h(\"b\", {}, title), reason.length > 0 ? \" \" : null, ...reason),\n );\n}\n\n/**\n * This function sets the value of a field and sends an `input` event that bubbles, as typing does.\n * Thus an example button changes a field, and the demo of the field shows the new value.\n */\nexport function setField(field: HTMLInputElement | HTMLTextAreaElement, value: string): void {\n field.value = value;\n field.dispatchEvent(new Event(\"input\", { bubbles: true }));\n}\n\n
|
|
1
|
+
{"version":3,"file":"demo.js","names":[],"sources":["../src/demo.ts"],"sourcesContent":["/**\n * The parts of a live demo on a page. The parts are a row of example buttons, the line of a verdict,\n * a field that a script fills and a text with marks. This module imports no Node.js module, so a site\n * can bundle it. Its style is in `@mark1russell7/site-pages/demo.css`.\n *\n * @packageDocumentation\n */\nimport { h, type Child } from \"./chrome.ts\";\n\n/** An example of a demo: the label of its button and the value that a click gives. */\nexport type Example = readonly [label: string, value: string];\n\n/**\n * This function fills a row with one button for each example, and gives the buttons. A click on a\n * button starts `pick` with the value of its example. When the value is not the label, the `title` of\n * the button is the value, so a pointer shows the full value.\n */\nexport function examples(row: HTMLElement, items: readonly Example[], pick: (value: string) => void): HTMLButtonElement[] {\n const buttons = items.map(([label, value]) => {\n const button = h(\"button\", { type: \"button\", class: \"sp-example\", title: value === label ? undefined : value }, label);\n button.addEventListener(\"click\", () => pick(value));\n return button;\n });\n row.replaceChildren(...buttons);\n return buttons;\n}\n\n/**\n * This function makes the line of a verdict: a mark, a title in bold and a reason. The mark is a check\n * for a pass and a cross for a fail. Its label tells the same to a screen reader, so the color is not\n * the only cue. The title has no punctuation of its own: give \"Correct:\" for a colon.\n */\nexport function verdict(pass: boolean, title: Child, ...reason: readonly Child[]): HTMLDivElement {\n return h(\n \"div\",\n { class: pass ? \"sp-verdict sp-pass\" : \"sp-verdict sp-fail\" },\n h(\"span\", { class: \"sp-mark\", role: \"img\", \"aria-label\": pass ? \"Pass\" : \"Fail\" }, pass ? \"✓\" : \"✕\"),\n h(\"div\", {}, h(\"b\", {}, title), reason.length > 0 ? \" \" : null, ...reason),\n );\n}\n\n/**\n * This function sets the value of a field and sends an `input` event that bubbles, as typing does.\n * Thus an example button changes a field, and the demo of the field shows the new value.\n */\nexport function setField(field: HTMLInputElement | HTMLTextAreaElement, value: string): void {\n field.value = value;\n field.dispatchEvent(new Event(\"input\", { bubbles: true }));\n}\n\n/**\n * A part of a text. `markedText` puts a `mark` element on a part with `hit`. The functions `partsAt` and `partsOf` of\n * `@mark1russell7/text/parts` give the parts of a text.\n */\nexport interface TextPart {\n readonly text: string;\n readonly hit: boolean;\n}\n\n/**\n * This function shows a text in a `pre` box, with a `mark` element on each part with `hit`. The box is\n * a group with the label, so a screen reader names it. A text with no parts shows \"(empty)\".\n */\nexport function markedText(parts: readonly TextPart[], label: string): HTMLPreElement {\n const nodes = parts.filter((part) => part.text !== \"\").map((part) => (part.hit ? h(\"mark\", {}, part.text) : part.text));\n return h(\"pre\", { class: \"sp-text\", role: \"group\", \"aria-label\": label }, nodes.length > 0 ? nodes : h(\"span\", { class: \"sp-empty\" }, \"(empty)\"));\n}\n"],"mappings":";;;;;;;;;;;;;;AAiBA,SAAgB,SAAS,KAAkB,OAA2B,MAAoD;CACxH,MAAM,UAAU,MAAM,KAAK,CAAC,OAAO,WAAW;EAC5C,MAAM,SAAS,EAAE,UAAU;GAAE,MAAM;GAAU,OAAO;GAAc,OAAO,UAAU,QAAQ,KAAA,IAAY;EAAM,GAAG,KAAK;EACrH,OAAO,iBAAiB,eAAe,KAAK,KAAK,CAAC;EAClD,OAAO;CACT,CAAC;CACD,IAAI,gBAAgB,GAAG,OAAO;CAC9B,OAAO;AACT;;;;;;AAOA,SAAgB,QAAQ,MAAe,OAAc,GAAG,QAA0C;CAChG,OAAO,EACL,OACA,EAAE,OAAO,OAAO,uBAAuB,qBAAqB,GAC5D,EAAE,QAAQ;EAAE,OAAO;EAAW,MAAM;EAAO,cAAc,OAAO,SAAS;CAAO,GAAG,OAAO,MAAM,GAAG,GACnG,EAAE,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,KAAK,GAAG,OAAO,SAAS,IAAI,MAAM,MAAM,GAAG,MAAM,CAC3E;AACF;;;;;AAMA,SAAgB,SAAS,OAA+C,OAAqB;CAC3F,MAAM,QAAQ;CACd,MAAM,cAAc,IAAI,MAAM,SAAS,EAAE,SAAS,KAAK,CAAC,CAAC;AAC3D;;;;;AAeA,SAAgB,WAAW,OAA4B,OAA+B;CACpF,MAAM,QAAQ,MAAM,QAAQ,SAAS,KAAK,SAAS,EAAE,CAAC,CAAC,KAAK,SAAU,KAAK,MAAM,EAAE,QAAQ,CAAC,GAAG,KAAK,IAAI,IAAI,KAAK,IAAK;CACtH,OAAO,EAAE,OAAO;EAAE,OAAO;EAAW,MAAM;EAAS,cAAc;CAAM,GAAG,MAAM,SAAS,IAAI,QAAQ,EAAE,QAAQ,EAAE,OAAO,WAAW,GAAG,SAAS,CAAC;AAClJ"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@mark1russell7/site-pages",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.6.0",
|
|
5
5
|
"description": "A release timeline page and a live status page for the site of a GitHub repository: JSON data and standalone HTML, made at deploy time.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"github-pages",
|
|
@@ -47,6 +47,11 @@
|
|
|
47
47
|
"import": "./build/explorer/index.js",
|
|
48
48
|
"default": "./build/explorer/index.js"
|
|
49
49
|
},
|
|
50
|
+
"./config": {
|
|
51
|
+
"types": "./build/config/site-config.d.ts",
|
|
52
|
+
"import": "./build/config/site-config.js",
|
|
53
|
+
"default": "./build/config/site-config.js"
|
|
54
|
+
},
|
|
50
55
|
"./vite": {
|
|
51
56
|
"types": "./build/vite.d.ts",
|
|
52
57
|
"import": "./build/vite.js",
|