@heroiclands/package-build 22.4.4 → 22.4.6

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.
@@ -0,0 +1,95 @@
1
+ /**
2
+ * The bearing the other end of a relation states, or `undefined` for a value
3
+ * that is not a bearing.
4
+ *
5
+ * @param {unknown} bearing - A bearing.
6
+ * @returns {string|undefined} The one four steps around the compass.
7
+ */
8
+ export function oppositeBearing(bearing: unknown): string | undefined;
9
+ /**
10
+ * Check a place note's `data.borders`.
11
+ *
12
+ * Every `to` is a shortcode a place declares, every `bearing` is one of the
13
+ * eight, no pair is listed twice, no target is the note's own parent or child,
14
+ * and the other end states the pair back at the opposite bearing — a missing
15
+ * reciprocal is a warning naming both notes, a wrong one an error.
16
+ *
17
+ * @param {object} note - The note, as the link index hands it over.
18
+ * @param {object} [opts]
19
+ * @param {object} [opts.index] - The link index, for resolving `to`.
20
+ * @returns {object[]} Findings.
21
+ */
22
+ export function checkBorders(note: object, { index }?: {
23
+ index?: object | undefined;
24
+ }): object[];
25
+ /**
26
+ * Check a place note's `data.routes`.
27
+ *
28
+ * As {@link checkBorders}, plus: `mode` and `days` are required and from
29
+ * their sets, `terrain` is from the registry and crossable by the mode, a pair
30
+ * appears once per mode, and the other end states the pair back by the same
31
+ * mode, at the opposite bearing, with the same days.
32
+ *
33
+ * @param {object} note - The note, as the link index hands it over.
34
+ * @param {object} [opts]
35
+ * @param {object} [opts.index] - The link index, for resolving `to`.
36
+ * @returns {object[]} Findings.
37
+ */
38
+ export function checkRoutes(note: object, { index }?: {
39
+ index?: object | undefined;
40
+ }): object[];
41
+ /**
42
+ * The eight compass bearings, clockwise from north.
43
+ *
44
+ * Where a neighbour or a destination lies from the place stating it. The
45
+ * order is load-bearing: {@link oppositeBearing} reads four steps around it.
46
+ *
47
+ * @type {readonly string[]}
48
+ */
49
+ export const BEARINGS: readonly string[];
50
+ /**
51
+ * The modes a route is travelled by: `land`, `boat` on a river or a lake,
52
+ * `ship` on open sea.
53
+ *
54
+ * @type {readonly string[]}
55
+ */
56
+ export const ROUTE_MODES: readonly string[];
57
+ /**
58
+ * The days markers a route may state.
59
+ *
60
+ * Each is "about this, under normal conditions": `10`, `20` and `30` are one,
61
+ * two and three ten-day weeks, `180` is many months, `360` is "who knows".
62
+ *
63
+ * @type {readonly number[]}
64
+ */
65
+ export const TRAVEL_DAYS: readonly number[];
66
+ /**
67
+ * The terrain registry, each terrain naming the modes that cross it.
68
+ *
69
+ * A land terrain is crossed by land alone; open sea by ship; a river or a lake
70
+ * by boat; a coast by all three, because a coast road and a coasting voyage
71
+ * are both journeys along it.
72
+ *
73
+ * @type {Readonly<Record<string, readonly string[]>>}
74
+ */
75
+ export const TERRAIN_MODES: Readonly<Record<string, readonly string[]>>;
76
+ /**
77
+ * The terrain names, in registry order — the closed set a `terrain` list
78
+ * draws from.
79
+ *
80
+ * @type {readonly string[]}
81
+ */
82
+ export const TERRAINS: readonly string[];
83
+ /**
84
+ * The keys a `borders` entry may carry. Both are required.
85
+ *
86
+ * @type {readonly string[]}
87
+ */
88
+ export const BORDER_KEYS: readonly string[];
89
+ /**
90
+ * The keys a `routes` entry may carry. `to`, `bearing`, `mode` and `days` are
91
+ * required; `terrain` and `leagues` are optional.
92
+ *
93
+ * @type {readonly string[]}
94
+ */
95
+ export const ROUTE_KEYS: readonly string[];
@@ -139,7 +139,7 @@ export const HUGO_CONTENT: "build/hugo/content";
139
139
  * The directory that is deployed, relative to the repository root.
140
140
  *
141
141
  * Hugo renders into `<DEPLOY_ROOT>/<contentPackage>/`; `package-build
142
- * site-root` writes `_headers` and `_redirects` beside it.
142
+ * site-root` writes `_headers` beside it and the search index inside it.
143
143
  */
144
144
  export const DEPLOY_ROOT: "build/site";
145
145
  /** The npm package the shared theme arrives as. */
@@ -27,29 +27,67 @@ export function noindexHeaders(): string[];
27
27
  * @returns {string} The file's contents.
28
28
  */
29
29
  export function headers(): string;
30
+ export function indexSite(where: {
31
+ site: string;
32
+ output: string;
33
+ }): Promise<{
34
+ pages: number;
35
+ }>;
30
36
  /**
31
- * Write `_headers` beside the rendered site, and remove any `_redirects`.
37
+ * Write `_headers` beside the rendered site, remove any `_redirects`, and
38
+ * index the site for search.
32
39
  *
33
40
  * The removal is part of owning the root: a `_redirects` this build did not
34
41
  * write is one an earlier build left, and Cloudflare Pages applies whatever
35
42
  * sits there. Left in place it would redirect the prefix root — the homepage —
36
- * to an address nothing publishes.
43
+ * to an address nothing publishes. The same holds for a `pagefind/` left by an
44
+ * earlier build when `search` is off: deployed, it is a working search over
45
+ * pages that may no longer exist, so it goes too.
46
+ *
47
+ * `_headers` is written before the index is built, so a failed index leaves
48
+ * the root files as they would be — the failure is the indexer's, reported as
49
+ * one finding naming the rendered site, and nothing else about the deployment
50
+ * is in doubt.
37
51
  *
38
52
  * @param {object} options - Options.
39
53
  * @param {string} options.pkg - The content package name, which is also the
40
54
  * directory Hugo rendered into.
41
55
  * @param {string} options.out - The directory that is deployed.
42
- * @returns {{files: string[]}} The files written.
56
+ * @param {boolean} [options.search] - Whether to build the search index;
57
+ * `site.search` in the configuration. Default `true`.
58
+ * @param {SiteIndexer} [options.indexer] - What builds it. Default
59
+ * {@link indexSite}.
60
+ * @returns {Promise<{files: string[], search: {dir: string, pages: number}|null}>}
61
+ * The files written, and the index — where it is and how many pages it
62
+ * holds — or `null` when none was built.
43
63
  * @throws {Error} When no rendered site is there, which means the site build
44
64
  * has not run and writing root files would publish a deployment with nothing
45
- * under the prefix.
65
+ * under the prefix; or, located at the rendered site, when the indexer
66
+ * fails.
46
67
  */
47
- export function writeSiteRoot({ pkg, out }: {
68
+ export function writeSiteRoot({ pkg, out, search, indexer }: {
48
69
  pkg: string;
49
70
  out: string;
50
- }): {
71
+ search?: boolean | undefined;
72
+ indexer?: SiteIndexer | undefined;
73
+ }): Promise<{
51
74
  files: string[];
52
- };
75
+ search: {
76
+ dir: string;
77
+ pages: number;
78
+ } | null;
79
+ }>;
80
+ /**
81
+ * The directory the search index is written to, inside the rendered site.
82
+ *
83
+ * Pagefind's own default, and the one its browser bundle derives the site's
84
+ * base URL from: `pagefind.js` at `/<package>/pagefind/pagefind.js` means
85
+ * every result's `url` is joined onto `/<package>/`, so nothing about the
86
+ * prefix is configured on either side.
87
+ *
88
+ * @type {string}
89
+ */
90
+ export const SEARCH_DIR: string;
53
91
  /**
54
92
  * The namespace the routing layer derives a package's origin in.
55
93
  *
@@ -60,3 +98,17 @@ export function writeSiteRoot({ pkg, out }: {
60
98
  * @type {string}
61
99
  */
62
100
  export const ORIGIN_SUFFIX: string;
101
+ /**
102
+ * What runs the search indexer over a rendered site.
103
+ *
104
+ * {@link indexSite} is the one the command uses; a test hands
105
+ * {@link writeSiteRoot} a stand-in, so the step's own contract — what it is
106
+ * given, when it runs, how its failure is reported — is checked without a
107
+ * binary.
108
+ */
109
+ export type SiteIndexer = (where: {
110
+ site: string;
111
+ output: string;
112
+ }) => Promise<{
113
+ pages: number;
114
+ }>;