@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.
- package/CLAUDE.md +4 -1
- package/components/BookLink.astro +3 -2
- package/dist/index.d.ts +8 -70
- package/dist/index.mjs +21 -4
- package/dist/lib/nav-href.d.ts +66 -0
- package/dist/lib/nav-href.mjs +44 -0
- package/dist/schemas.d.ts +1 -1
- package/dist/{types-CZrkqzpC.d.ts → types-DgSlAew3.d.ts} +32 -8
- package/package.json +7 -4
- package/recipes/09-validation.md +51 -4
- package/recipes/22-responsive-nav-and-multibook-routing.md +5 -0
- package/scripts/authored-links.mjs +328 -0
- package/scripts/build-labels.mjs +88 -34
- package/scripts/resolve-book-config.mjs +90 -2
- package/scripts/validate.mjs +328 -44
- package/scripts/walk-mdx.mjs +122 -8
- package/src/lib/book-link.ts +25 -5
package/src/lib/book-link.ts
CHANGED
|
@@ -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
|
-
*
|
|
14
|
-
*
|
|
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:
|
|
25
|
+
siblingBooks: SiblingBooks | null | undefined,
|
|
18
26
|
book: string,
|
|
19
27
|
to: string,
|
|
20
28
|
): string {
|
|
21
|
-
const
|
|
22
|
-
|
|
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
|
}
|