@mark1russell7/site-pages 0.4.0 → 0.4.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.
package/README.md CHANGED
@@ -59,6 +59,8 @@ site-pages check --out dist --repo owner/name --pages /,/releases/ --probe site-
59
59
  site-pages check --url https://owner.github.io/name/
60
60
  ```
61
61
 
62
+ Before the measure, the check scrolls each view to its end, one screen at a time, and back to the top. Thus a part that starts when it comes into view starts first. An example is an Astro island with `client:visible` below the first screen. Then the check waits until no Astro island has the attribute `ssr`, for at most 10 seconds.
63
+
62
64
  A view fails for each of these problems:
63
65
 
64
66
  - The page is wider than the screen, or an element goes past the right edge. An element in a box that scrolls or clips does not count here.
@@ -70,6 +72,7 @@ A view fails for each of these problems:
70
72
  - A request to the site fails, or gets a status of 400 or more.
71
73
  - A script or a style sheet does not load, from any origin. An example is a module script that imports `node:perf_hooks`.
72
74
  - A check of the probe fails, or the probe makes no check.
75
+ - An Astro island does not start in the time limit. A hidden island and an island of a media query that does not match do not count.
73
76
 
74
77
  The text of the problem has the element, the box, the two widths, the width of the view and the start of the text. For example:
75
78
 
@@ -140,6 +143,60 @@ The folder of `--shots` gets a screenshot of each view, `report.json` and `summa
140
143
 
141
144
  The check finds a browser in this order: `--browser`, `$SITE_CHECK_BROWSER`, the newest Chromium of Playwright, and then Chrome or Edge. The folder `src/check` imports only Node.js. Thus Node.js 22.18 or later can start `src/check/main.ts` with no install. The workflow `reusable-pages.yml` of the template uses it this way.
142
145
 
146
+ ## The site bar
147
+
148
+ The command `site-pages bar` writes one shared bar into each HTML page of a built site. The bar comes first in the body of each page.
149
+
150
+ ```sh
151
+ site-pages bar --out dist --repo owner/name --pages "Demo=demo/,Docs=docs/" --site-pages --npm @owner/name
152
+ ```
153
+
154
+ - The bar has the portfolio of the owner and the name of the site. The name links to the home.
155
+ - It has a link to the home, to each page of `--pages`, and to Releases and Status with `--site-pages`. The link of the current page has `aria-current="page"`.
156
+ - It also links to the repository on GitHub, and to npm with `--npm`.
157
+ - The bar takes the place of the header of the Releases page and the Status page.
158
+ - Its CSS has its own class names, so the CSS of the site does not change the bar. It follows the light and the dark scheme. Its rows wrap at 360 px.
159
+ - The command can start two times on one folder. The second start gives the same pages.
160
+
161
+ In `reusable-pages.yml`, the input `site-bar: true` starts the command before the upload. Then `site-pages nav --require-bar` crawls the built site, and a failure stops the deploy.
162
+
163
+ ## The scroll cue of the built pages
164
+
165
+ The command `site-pages cue` changes each code block (`pre`) of each HTML page of a built site. Each block gets the class `scroll-cue` and a place in the tab order. It also writes the style `scroll-cue.css` into each changed page.
166
+
167
+ ```sh
168
+ site-pages cue --out dist
169
+ ```
170
+
171
+ - A code block that is wider than its box shows a fade at the edge with more content. A block that is not wider shows no cue.
172
+ - A block with `data-overflow-ok` or with the class `scroll-cue` stays as it is. The text of `script`, `style` and `textarea` does not change.
173
+ - In a browser with no scroll timelines, a small script gives `--scroll-cue-bg` the background color of the block. Thus the block keeps the color of its theme.
174
+ - The command can start two times on one folder. The second start gives the same pages.
175
+
176
+ In `reusable-pages.yml`, the input `scroll-cue` (default `true`) starts the command before the site check and the upload.
177
+
178
+ ## The navigation of a site
179
+
180
+ The command `site-pages nav` opens the home page of a site in a headless Chromium. It follows the links that the page shows, page by page, and counts the clicks from home.
181
+
182
+ ```sh
183
+ site-pages nav --url https://owner.github.io/name/ --shots nav
184
+ site-pages nav --out dist --repo owner/name --max-clicks 2
185
+ ```
186
+
187
+ The command fails for each of these problems:
188
+
189
+ - A page of `sitemap.xml` is more than `--max-clicks` clicks from home, or no chain of links from home reaches it.
190
+ - A page shows no link back to home at 1280 px or at 360 px. A hidden link does not count.
191
+ - A link to a page of the site opens a new tab. Then the back button of the browser cannot go back.
192
+ - A link goes to a page that gives a status of 400 or more.
193
+ - A click on a link to `releases/` or `status/` does not show the page of site-pages. A single-page application can catch the click and show its own page.
194
+ - With `--require-bar`, a page has no shared site bar.
195
+
196
+ The crawl opens at most `--max-pages` pages (default: 60). When it stops at this limit, the pages that it did not open are a "no read". A no-read is not a pass: the command fails, and `report.json` lists the pages in `unread`. The summary shows their count and their paths. In `site-audit.yml`, each no-read is a warning on the check of the pull request.
197
+
198
+ The folder of `--shots` gets `report.json`, `summary.md` and screenshots of the home, the releases and the status pages, at 1280 px and 360 px.
199
+
143
200
  ## The freshness of a measured page
144
201
 
145
202
  A measured page shows numbers from a run. The numbers become old when the run becomes old or when an engine has a new release. A site keeps one file of data stamps. Each stamp names the page, its runs, the date of each run and the engine versions of each run. The gate reads this file:
@@ -219,6 +276,20 @@ For a monorepo with one version for all its packages, give `--group` and the nam
219
276
 
220
277
  The option `from` leaves out older sections. The option `fixedGroup` passes a section with no change or with only PATCH changes, because its raise comes from another package of the group.
221
278
 
279
+ ### The changelog gate
280
+
281
+ The command `build` reads each changelog with `changelogReading`. A repository puts the oldest version of its gate in its root `package.json`:
282
+
283
+ ```json
284
+ { "sitePages": { "changelogFrom": "0.1.0" } }
285
+ ```
286
+
287
+ - With the field, a fault in a section of that version or newer stops the build with code 1. The error names each section and its fault.
288
+ - Without the field, the build gives a warning with the count of the sections with a fault, and it does not fail.
289
+ - In both cases, `status.json` holds the reading in the field `changelog`, and the Status page shows the count. A reader of all the sites can thus list each repository, also a repository with no gate.
290
+
291
+ To join the gate, a repository adds the field with no change to its code. Older sections can follow older habits, so the repository picks the first version that has no fault.
292
+
222
293
  `sectionMarksBreak(section)` tells if the text of a section marks a break. The marks are the heading `### Breaking` and the words "has breaking changes". A page that counts breaks uses this function.
223
294
 
224
295
  A repository can have no changelog and no GitHub release. Then each npm version of each package of `--packages` is a release:
@@ -420,6 +491,12 @@ The class sets `overflow-x: auto`. A browser with scroll timelines keeps the bac
420
491
  }
421
492
  ```
422
493
 
494
+ The fades run on a scroll timeline (`animation-timeline: scroll(self inline)`). In Chromium, `document.getAnimations()` gives each fade as a running animation with one iteration, and the fade does not end. A test that waits for the end of each animation, for example before an axe check of the contrast, then stops at its time limit. Such a test must skip each animation whose timeline is not `document.timeline`:
495
+
496
+ ```ts
497
+ const running = document.getAnimations().filter((a) => a.timeline === document.timeline && a.playState === "running");
498
+ ```
499
+
423
500
  Markdown has no way to set the class of a table or a code block. For a Markdown page, add the plugin `rehypeScrollCue` of the entry `@mark1russell7/site-pages/vite`. It gives the class and a tab stop to each table and each code block. A table also gets a label. A code block keeps a tab stop that it has:
424
501
 
425
502
  ```js
@@ -229,6 +229,47 @@ function changelogFaults(markdown, options = {}) {
229
229
  return faults;
230
230
  }
231
231
  /**
232
+ * This function reads the changelog files of a repository against the rules of a version section.
233
+ * With a `from` version, it examines the sections of that version and newer. With null, it examines all the sections.
234
+ *
235
+ * @throws RangeError when `from` is not a version
236
+ */
237
+ function changelogReading(changelogs, from) {
238
+ const core = from === null ? null : versionCore(from);
239
+ if (from !== null && core === null) throw new RangeError(`"${from}" is not a version.`);
240
+ let sections = 0;
241
+ const faults = [];
242
+ for (const { file, markdown } of changelogs) {
243
+ for (const section of versionSections(markdown)) {
244
+ const own = versionCore(section.version);
245
+ if (own !== null && (core === null || compareCores(own, core) >= 0)) sections += 1;
246
+ }
247
+ for (const fault of changelogFaults(markdown, from === null ? {} : { from })) faults.push({
248
+ file,
249
+ ...fault
250
+ });
251
+ }
252
+ return {
253
+ from,
254
+ sections,
255
+ faults
256
+ };
257
+ }
258
+ /**
259
+ * This function gives the problem of a changelog reading for the build, or null. A reading with a
260
+ * `from` version and a fault fails the build. A reading with no `from` version only reports.
261
+ */
262
+ function changelogGateProblem(reading, limit = 20) {
263
+ if (reading.from === null || reading.faults.length === 0) return null;
264
+ const lines = reading.faults.slice(0, limit).map((fault) => ` ${fault.file} ${fault.version}: ${fault.kind}${fault.statement === "" ? "" : ` ("${fault.statement.slice(0, 80)}")`}`);
265
+ const more = reading.faults.length > limit ? [` and ${reading.faults.length - limit} more`] : [];
266
+ return [
267
+ `${reading.faults.length} of ${reading.sections} version sections from ${reading.from} break the rules of a changelog section:`,
268
+ ...lines,
269
+ ...more
270
+ ].join("\n");
271
+ }
272
+ /**
232
273
  * This function gives the changes of the text of a GitHub release: one change for each top-level
233
274
  * list item. Fenced code is not read.
234
275
  */
@@ -1063,6 +1104,28 @@ function releaseReading(listed, sources, now = Date.now()) {
1063
1104
  inFlight
1064
1105
  };
1065
1106
  }
1107
+ /**
1108
+ * This function gives the oldest version that the changelog gate of a repository examines: the field
1109
+ * `sitePages.changelogFrom` of its root `package.json`. It gives null when the file or the field is not there.
1110
+ *
1111
+ * @throws ReleaseDataError when the field is not a version
1112
+ */
1113
+ function readChangelogFrom(repoDir) {
1114
+ const path = join(repoDir, "package.json");
1115
+ if (!existsSync(path)) return null;
1116
+ let manifest;
1117
+ try {
1118
+ manifest = JSON.parse(readFileSync(path, "utf8"));
1119
+ } catch {
1120
+ return null;
1121
+ }
1122
+ const settings = manifest.sitePages;
1123
+ if (settings === void 0 || settings === null || typeof settings !== "object") return null;
1124
+ const from = settings.changelogFrom;
1125
+ if (from === void 0) return null;
1126
+ if (typeof from !== "string" || !/^v?\d+\.\d+\.\d+$/.test(from)) throw new ReleaseDataError(`the field sitePages.changelogFrom of package.json must be a version, for example "0.1.0", not ${JSON.stringify(from)}.`);
1127
+ return from;
1128
+ }
1066
1129
  /** The default patterns of the changelog files: the first pattern that finds a file wins. */
1067
1130
  const DEFAULT_CHANGELOGS = ["packages/*/CHANGELOG.md", "CHANGELOG.md"];
1068
1131
  /**
@@ -2369,6 +2432,20 @@ function measures(data) {
2369
2432
  const commit = link(`https://github.com/${data.source.github}/commit/${kpi.commit}`, `<code>${kpi.commit.slice(0, 7)}</code>`);
2370
2433
  return `<section class="sp-section" aria-labelledby="measures"><h2 id="measures">Measures</h2><p>${ownDates ? "The data date of the file is" : "The data of these numbers is from"} <time datetime="${escapeHtml(kpi.at)}" data-sp-data-date>${escapeHtml(longDate(kpi.at))}</time>. The build of ${commit} published them.</p>` + (engines.length > 0 ? `<p>The engines of the data: ${listText(engines.map((engine) => `<code>${escapeHtml(engine.name)}</code> ${escapeHtml(engine.version)}`))}.</p>` : "") + `<div class="sp-table-box" tabindex="0" role="region" aria-label="Measures"><table class="sp-table"><thead><tr><th scope="col">Measure</th><th scope="col">Value</th>${ownDates ? "<th scope=\"col\">Data date</th>" : ""}</tr></thead><tbody>${rows}</tbody></table></div>` + limits + "</section>";
2371
2434
  }
2435
+ /**
2436
+ * This function renders the reading of the changelogs. It shows the count of the version sections that break
2437
+ * the rules, and the version that the gate starts from. A repository with no gate sees its count, so the gap stays in view.
2438
+ */
2439
+ function changelog(data) {
2440
+ const { changelog: reading } = data;
2441
+ if (reading === void 0) return "";
2442
+ const count = reading.faults.length;
2443
+ const scope = reading.from === null ? `of the ${plural(reading.sections, "version section")} of the changelogs` : `of the ${plural(reading.sections, "version section")} from ${escapeHtml(reading.from)}`;
2444
+ const gate = reading.from === null ? "The build does not fail on a fault, because <code>package.json</code> has no field <code>sitePages.changelogFrom</code>." : `The build fails on a fault in a section from ${escapeHtml(reading.from)}, the field <code>sitePages.changelogFrom</code> of <code>package.json</code>.`;
2445
+ const shown = reading.faults.slice(0, 10);
2446
+ const list = shown.length === 0 ? "" : `<ul>${shown.map((fault) => `<li><code>${escapeHtml(fault.file)}</code> ${escapeHtml(fault.version)}: ${escapeHtml(fault.kind)}</li>`).join("")}</ul>` + (count > shown.length ? `<p class="sp-small sp-muted">The list shows the first ${shown.length}.</p>` : "");
2447
+ return `<section class="sp-section" aria-labelledby="changelog"><h2 id="changelog">Changelog</h2><p data-sp-changelog-faults="${count}">${count === 0 ? "No section" : plural(count, "section")} ${scope} ${count <= 1 ? "breaks" : "break"} the rules of a changelog section. ${gate}</p>` + list + "</section>";
2448
+ }
2372
2449
  function when(date) {
2373
2450
  const text = escapeHtml(longDate(date));
2374
2451
  return `<time datetime="${escapeHtml(date)}" title="${text}" data-sp-rel>${text}</time>`;
@@ -2505,7 +2582,7 @@ function renderStatusPage(data, options) {
2505
2582
  title: "Status",
2506
2583
  description: lead,
2507
2584
  current: "status",
2508
- main: `<h1>Status</h1><p class="sp-lead">${escapeHtml(lead)}</p><p class="sp-small sp-muted">The build reads the roadmap file and GitHub again after each commit and on a schedule.</p>` + measures(data) + (data.source.roadmap ? openWork(data) : "") + pullRequests(data) + issues(data),
2585
+ main: `<h1>Status</h1><p class="sp-lead">${escapeHtml(lead)}</p><p class="sp-small sp-muted">The build reads the roadmap file and GitHub again after each commit and on a schedule.</p>` + measures(data) + changelog(data) + (data.source.roadmap ? openWork(data) : "") + pullRequests(data) + issues(data),
2509
2586
  script: STATUS_SCRIPT
2510
2587
  }, options);
2511
2588
  }
@@ -2550,6 +2627,11 @@ async function build(options) {
2550
2627
  const [owner = "", repo = ""] = repository.split("/");
2551
2628
  const out = isAbsolute(options.out) ? options.out : resolve(repoDir, options.out);
2552
2629
  const fetcher = options.fetch ? { fetch: options.fetch } : {};
2630
+ const changelogs = readChangelogs(repoDir, options.changesets);
2631
+ const reading = changelogs.length === 0 ? void 0 : changelogReading(changelogs, readChangelogFrom(repoDir));
2632
+ const problem = reading === void 0 ? null : changelogGateProblem(reading);
2633
+ if (problem !== null) throw new ReleaseDataError(problem);
2634
+ if (reading !== void 0 && reading.from === null && reading.faults.length > 0) warn(`${reading.faults.length} of ${reading.sections} version sections of the changelogs break the rules of a changelog section. The build does not fail, because package.json has no field sitePages.changelogFrom.`);
2553
2635
  const releases = await readReleases({
2554
2636
  repoDir,
2555
2637
  repository,
@@ -2564,19 +2646,19 @@ async function build(options) {
2564
2646
  });
2565
2647
  const kpiPath = join(out, KPI_FILE);
2566
2648
  const kpi = existsSync(kpiPath) ? readKpi(readFileSync(kpiPath, "utf8"), Date.parse(now)) : void 0;
2567
- const board = await readStatusBoard({
2568
- repoDir,
2569
- roadmap: options.roadmap ?? null,
2570
- owner,
2571
- repo,
2572
- token: options.token,
2573
- commit,
2574
- generatedAt: now,
2575
- ...fetcher
2576
- });
2577
- const status = kpi === void 0 ? board : {
2578
- ...board,
2579
- kpi
2649
+ const status = {
2650
+ ...await readStatusBoard({
2651
+ repoDir,
2652
+ roadmap: options.roadmap ?? null,
2653
+ owner,
2654
+ repo,
2655
+ token: options.token,
2656
+ commit,
2657
+ generatedAt: now,
2658
+ ...fetcher
2659
+ }),
2660
+ ...kpi === void 0 ? {} : { kpi },
2661
+ ...reading === void 0 ? {} : { changelog: reading }
2580
2662
  };
2581
2663
  if (!status.github.available) warn(`the status page has no GitHub data: ${status.github.reason ?? "no reason"}.`);
2582
2664
  const files = [];
@@ -2732,6 +2814,6 @@ async function runCli(argv, io) {
2732
2814
  throw error;
2733
2815
  }
2734
2816
  }
2735
- export { githubReleases as $, STATUS_CLASSES as A, DEFAULT_CHANGELOGS as B, pageShell as C, utcDay as D, shortDate as E, plainText as F, releaseReading as G, mergeReleases as H, readStatusBoard as I, GITHUB_GRAPHQL as J, globFiles as K, roadmapItems as L, linksOf as M, markdownTables as N, OPEN_CLASSES as O, parseRoadmap as P, githubReleaseLag as Q, splitRow as R, BASE_CSS as S, longDate as T, readChangelogs as U, ReleaseDataError as V, readReleases as W, githubGreenRun as X, checkStateOf as Y, githubOpenWork as Z, renderReleasesPage as _, runCli as a, headingAnchor as at, releaseSummary as b, STATUS_SCRIPT as c, sectionMarksBreak as ct, renderStatusPage as d, greenRunOf as et, sectionsOf as f, releasesLead as g, RELEASES_SCRIPT as h, parseBuildArgs as i, firstSentence as it, buildStatusBoard as j, RoadmapParseError as k, classCounts as l, statusLead as m, UsageError as n, changelogFaults as nt, TYPESCRIPT_PROBE as o, parseChangelog as ot, slugOf as p, GITHUB_API as q, build as r, changelogVersions as rt, probeScript as s, releaseBodyEntries as st, HELP as t, releaseLagOf as tt, openGroups as u, laneCenter as v, dayRange as w, timelineLayout as x, oldestFirst as y, statusClassOf as z };
2817
+ export { githubReleaseLag as $, STATUS_CLASSES as A, DEFAULT_CHANGELOGS as B, pageShell as C, utcDay as D, shortDate as E, plainText as F, readReleases as G, mergeReleases as H, readStatusBoard as I, GITHUB_API as J, releaseReading as K, roadmapItems as L, linksOf as M, markdownTables as N, OPEN_CLASSES as O, parseRoadmap as P, githubOpenWork as Q, splitRow as R, BASE_CSS as S, longDate as T, readChangelogFrom as U, ReleaseDataError as V, readChangelogs as W, checkStateOf as X, GITHUB_GRAPHQL as Y, githubGreenRun as Z, renderReleasesPage as _, runCli as a, changelogReading as at, releaseSummary as b, STATUS_SCRIPT as c, headingAnchor as ct, renderStatusPage as d, sectionMarksBreak as dt, githubReleases as et, sectionsOf as f, releasesLead as g, RELEASES_SCRIPT as h, parseBuildArgs as i, changelogGateProblem as it, buildStatusBoard as j, RoadmapParseError as k, classCounts as l, parseChangelog as lt, statusLead as m, UsageError as n, releaseLagOf as nt, TYPESCRIPT_PROBE as o, changelogVersions as ot, slugOf as p, globFiles as q, build as r, changelogFaults as rt, probeScript as s, firstSentence as st, HELP as t, greenRunOf as tt, openGroups as u, releaseBodyEntries as ut, laneCenter as v, dayRange as w, timelineLayout as x, oldestFirst as y, statusClassOf as z };
2736
2818
 
2737
2819
  //# sourceMappingURL=build.js.map