@brandon_m_behring/book-scaffold-astro 4.28.0 → 4.30.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.
@@ -10,16 +10,27 @@
10
10
  * sibling redeploys or extracts to its own repo. An unknown `book` THROWS
11
11
  * rather than emitting a dead cross-origin link (fail-loud, like #109).
12
12
  *
13
- * Phase 1 (this): registry-backed href + fail-loud on unknown book. Phase 2
14
- * (deferred): validate the `to` id against a vendored sibling `labels.json`.
13
+ * #147 extends each registry entry from a URL string to the backward-compatible
14
+ * `{ url, labels? }` descriptor. Runtime href resolution uses `url`; the
15
+ * validator uses `labels` to check literal sibling path/fragment targets.
15
16
  */
17
+ import type { SiblingBookEntry, SiblingBooks } from '../types.js';
18
+
19
+ function entryUrl(entry: SiblingBookEntry | undefined): string | undefined {
20
+ if (typeof entry === 'string') return entry;
21
+ return entry?.url;
22
+ }
23
+
16
24
  export function resolveBookHref(
17
- siblingBooks: Record<string, string> | null | undefined,
25
+ siblingBooks: SiblingBooks | null | undefined,
18
26
  book: string,
19
27
  to: string,
20
28
  ): string {
21
- const base = siblingBooks?.[book];
22
- if (!base) {
29
+ const registered =
30
+ siblingBooks !== null &&
31
+ siblingBooks !== undefined &&
32
+ Object.prototype.hasOwnProperty.call(siblingBooks, book);
33
+ if (!registered) {
23
34
  const known = siblingBooks ? Object.keys(siblingBooks) : [];
24
35
  throw new Error(
25
36
  `<BookLink book="${book}">: unknown sibling book. Register it in ` +
@@ -28,5 +39,14 @@ export function resolveBookHref(
28
39
  '.',
29
40
  );
30
41
  }
42
+
43
+ const entry = siblingBooks![book];
44
+ const base = entryUrl(entry);
45
+ if (typeof base !== 'string' || base.length === 0) {
46
+ throw new Error(
47
+ `<BookLink book="${book}">: invalid siblingBooks entry. Expected a URL ` +
48
+ 'string or { url: "https://…", labels?: "./path/to/labels.json" }.',
49
+ );
50
+ }
31
51
  return `${base.replace(/\/+$/, '')}/${to.replace(/^\/+/, '')}`;
32
52
  }