docpensieve 0.1.5 → 0.2.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.
@@ -0,0 +1,1033 @@
1
+ ---
2
+ title: API
3
+ description: Every export of the five packages, from their JSDoc.
4
+ tags: [reference, api]
5
+ ---
6
+
7
+ # API
8
+
9
+ {/* Generated by scripts/api-reference.mjs from the JSDoc of the sources: run npm run api:docs rather than editing this page. */}
10
+
11
+ The five packages are published together, at the same version. Most
12
+ projects only need the `docpensieve` command; the packages below are for
13
+ what goes further — a script that builds a site, a theme of your own.
14
+
15
+ Each entry comes from the JSDoc of the source, which the type checker
16
+ verifies: it cannot drift from the code without the build noticing.
17
+
18
+ ## `@docpensieve/shared`
19
+
20
+ Constants, errors and slugs, shared by every package.
21
+
22
+ ### `DOC_EXTENSIONS`
23
+
24
+ `DOC_EXTENSIONS`
25
+
26
+ File extensions recognised as documentation pages.
27
+
28
+ ### `CONFIG_FILENAME`
29
+
30
+ `CONFIG_FILENAME`
31
+
32
+ Name of the configuration file `init` writes at the project root.
33
+
34
+ `.mjs` rather than `.js`: the file is an ES module, and Node reads a `.js`
35
+ file as one only when the nearest package.json declares "type": "module".
36
+ Elsewhere it warns on every build — or refuses the file outright when that
37
+ package.json says "commonjs", as `npm init -y` now writes.
38
+
39
+ ### `CONFIG_FILENAMES`
40
+
41
+ `CONFIG_FILENAMES`
42
+
43
+ Names accepted for the configuration file, in the order they are looked for.
44
+ The `.js` spelling still works in a project whose package.json declares
45
+ "type": "module".
46
+
47
+ ### `THEME_FOLDER`
48
+
49
+ `THEME_FOLDER`
50
+
51
+ Folder of the project's own stylesheets, at its root. Every `.css` file in
52
+ it is appended to the site's stylesheet, after the theme's.
53
+
54
+ ### `DEFAULT_OUT_DIR`
55
+
56
+ `DEFAULT_OUT_DIR`
57
+
58
+ Default output directory of a build.
59
+
60
+ ### `VERSIONS_MANIFEST`
61
+
62
+ `VERSIONS_MANIFEST`
63
+
64
+ Version manifest written by every build.
65
+
66
+ ### `INDEX_SLUGS`
67
+
68
+ `INDEX_SLUGS`
69
+
70
+ Page slugs treated as the root of their folder (they take the folder's own URL).
71
+
72
+ ### `JSONLD_TYPES`
73
+
74
+ `JSONLD_TYPES`
75
+
76
+ JSON-LD types supported by the `jsonld.type` frontmatter field.
77
+
78
+ ### `THEME_FRAMEWORKS`
79
+
80
+ `THEME_FRAMEWORKS`
81
+
82
+ CSS frameworks known to the ThemeEngine.
83
+
84
+ ### `PAGE_LAYOUTS`
85
+
86
+ `PAGE_LAYOUTS`
87
+
88
+ Layouts accepted in a page's frontmatter.
89
+
90
+ `doc` is the documentation layout: menu on the left, table of contents on
91
+ the right, content held to reading width. `home` removes all three, which
92
+ is what a landing page expects.
93
+
94
+ ### `DEFAULT_THEME_CLASSES`
95
+
96
+ `DEFAULT_THEME_CLASSES`
97
+
98
+ Class slots of the page shell.
99
+
100
+ Templates hard-code no class: they ask the theme for the class of each
101
+ slot. A provider only redefines what it wants to change; everything else
102
+ falls back to these values. That is what lets a single template render
103
+ either `dp-nav` or a string of Tailwind utilities.
104
+
105
+ This table is shared: `core` reads it in its templates, `theme` extends it
106
+ in its providers.
107
+
108
+ ### `DocPensieveError`
109
+
110
+ `class DocPensieveError`
111
+
112
+ Expected domain error — the CLI prints it without a stack trace.
113
+
114
+ ### `ConfigError`
115
+
116
+ `class ConfigError`
117
+
118
+ Configuration missing, unreadable or invalid.
119
+
120
+ ### `LoaderError`
121
+
122
+ `class LoaderError`
123
+
124
+ A source file could not be read or parsed.
125
+
126
+ ### `CompileError`
127
+
128
+ `class CompileError`
129
+
130
+ MDX/Markdown compilation failed.
131
+
132
+ ### `StructuredDataError`
133
+
134
+ `class StructuredDataError`
135
+
136
+ Invalid `jsonld` frontmatter or inconsistent structured data.
137
+
138
+ ### `ThemeError`
139
+
140
+ `class ThemeError`
141
+
142
+ Theme provider missing, invalid, or whose compilation failed.
143
+
144
+ ### `GeneratorError`
145
+
146
+ `class GeneratorError`
147
+
148
+ The site could not be generated or written.
149
+
150
+ ### `NotImplementedError`
151
+
152
+ `class NotImplementedError`
153
+
154
+ Milestone not implemented yet — points to the roadmap section.
155
+
156
+ ### `slugify`
157
+
158
+ `slugify(input)`
159
+
160
+ Turns free text into a URL-safe slug.
161
+
162
+ Accents are decomposed then dropped (`Crème` → `creme`), which keeps URLs
163
+ readable instead of percent-encoded.
164
+
165
+ | Parameter | Type | |
166
+ | --- | --- | --- |
167
+ | `input` | `string` | |
168
+
169
+ **Returns** `string` — Lowercase slug, dash-separated.
170
+
171
+ ### `filePathToSlug`
172
+
173
+ `filePathToSlug(relativePath)`
174
+
175
+ Converts a file path, relative to the version folder, into a page slug.
176
+
177
+ Ordering prefixes are removed from every segment: they sort the sidebar,
178
+ they do not build the URL.
179
+
180
+ | Parameter | Type | |
181
+ | --- | --- | --- |
182
+ | `relativePath` | `string` | Path relative to the version folder. |
183
+
184
+ **Returns** `string` — Slug with no leading or trailing slash.
185
+
186
+ ### `assetPathToSlug`
187
+
188
+ `assetPathToSlug(relativePath)`
189
+
190
+ Maps an asset path into URL space.
191
+
192
+ Folders follow the page rule — ordering prefix removed, segment slugified —
193
+ so that `02-guide/diagram.png` lands under `/guide/`, where the pages of the
194
+ same folder expect it. Otherwise the sorting prefix, which never shows in a
195
+ page URL, would show in the URL of its images.
196
+
197
+ The file name itself stays untouched: it is the one the author writes in
198
+ their Markdown, and rewriting it would break the reference.
199
+
200
+ | Parameter | Type | |
201
+ | --- | --- | --- |
202
+ | `relativePath` | `string` | Path relative to the version folder. |
203
+
204
+ **Returns** `string` — Output path, slash-separated.
205
+
206
+ ### `blankSegments`
207
+
208
+ `blankSegments(relativePath)`
209
+
210
+ Segments of a path that leave nothing behind once slugified.
211
+
212
+ `slugify` only keeps Latin letters and digits: a name made entirely of
213
+ ideograms, or of punctuation, vanishes. For a page, that meant taking the
214
+ home page's URL; for a folder, disappearing from the address.
215
+
216
+ | Parameter | Type | |
217
+ | --- | --- | --- |
218
+ | `relativePath` | `string` | Path relative to the version folder. |
219
+
220
+ **Returns** `string[]` — The offending segments, extension removed.
221
+
222
+ ### `dirPathToSlug`
223
+
224
+ `dirPathToSlug(relativePath)`
225
+
226
+ Maps a **folder** path into URL space.
227
+
228
+ Sibling of `assetPathToSlug`, but with no file name to spare: every segment
229
+ goes through the page rule. Applying `assetPathToSlug` to a folder left its
230
+ last segment untouched — `02-guide` stayed `02-guide` — and every relative
231
+ target of a page in that folder missed the file actually copied.
232
+
233
+ | Parameter | Type | |
234
+ | --- | --- | --- |
235
+ | `relativePath` | `string` | Path relative to the version folder. |
236
+
237
+ **Returns** `string` — Output path, slash-separated.
238
+
239
+ ### `slugToUrl`
240
+
241
+ `slugToUrl(slug, [versionSlug])`
242
+
243
+ Converts a page slug into an absolute site URL (trailing slash included).
244
+
245
+ | Parameter | Type | |
246
+ | --- | --- | --- |
247
+ | `slug` | `string` | Slug produced by \{@link filePathToSlug\}. |
248
+ | `[versionSlug]` | `string` | When given, prefixes `/versions/<version>`. |
249
+
250
+ **Returns** `string` — URL starting and ending with `/`.
251
+
252
+ ### `humanizeSlug`
253
+
254
+ `humanizeSlug(segment)`
255
+
256
+ Turns a slug segment back into a readable label.
257
+
258
+ A deliberate, imperfect fallback: since `slugify` dropped the accents,
259
+ `creme-brulee` comes back as “Creme brulee”. Only use it when there is no
260
+ real title — the sidebar and the breadcrumb prefer the frontmatter title.
261
+
262
+ | Parameter | Type | |
263
+ | --- | --- | --- |
264
+ | `segment` | `string` | |
265
+
266
+ **Returns** `string`
267
+
268
+ ### `orderOf`
269
+
270
+ `orderOf(filename)`
271
+
272
+ Reads the ordering weight of a prefixed file name.
273
+
274
+ | Parameter | Type | |
275
+ | --- | --- | --- |
276
+ | `filename` | `string` | |
277
+
278
+ **Returns** `number` — The prefix number, or `Infinity` when absent (sorted last).
279
+
280
+ ## `@docpensieve/core`
281
+
282
+ Configuration, loading, compilation, structured data and generation.
283
+
284
+ ### `DEFAULT_CONFIG`
285
+
286
+ `DEFAULT_CONFIG`
287
+
288
+ Values applied when the user config leaves them out.
289
+
290
+ The type is spelled out: without it, TypeScript would infer
291
+ `versions: never[]` from the empty array and refuse every read of its
292
+ elements elsewhere in the file.
293
+
294
+ ### `defineConfig`
295
+
296
+ `defineConfig(config)`
297
+
298
+ Identity over the config, used only for autocompletion and type checking
299
+ in the editor.
300
+
301
+ | Parameter | Type | |
302
+ | --- | --- | --- |
303
+ | `config` | `T` | |
304
+
305
+ **Returns** `T`
306
+
307
+ ### `loadConfig`
308
+
309
+ `loadConfig([cwd])`
310
+
311
+ Loads the configuration file of a project folder.
312
+
313
+ `docpensieve.config.mjs` is looked for first, then `docpensieve.config.js`,
314
+ which a project whose package.json declares "type": "module" can still use.
315
+
316
+ | Parameter | Type | |
317
+ | --- | --- | --- |
318
+ | `[cwd]` | `string` | Project root. Default: `process.cwd()`. |
319
+
320
+ **Returns** `Promise<DocPensieveConfig>` — Normalised config.
321
+
322
+ **Throws** `ConfigError` — When no file, or two, are found, or when the file does not load or exports no object.
323
+
324
+ ### `normalizeConfig`
325
+
326
+ `normalizeConfig(userConfig)`
327
+
328
+ Merges the user config with the defaults and validates it.
329
+
330
+ | Parameter | Type | |
331
+ | --- | --- | --- |
332
+ | `userConfig` | `Record<string, unknown>` | |
333
+
334
+ **Returns** `DocPensieveConfig` — Normalised config.
335
+
336
+ **Throws** `ConfigError` — When the config is structurally invalid.
337
+
338
+ ### `resolveVersion`
339
+
340
+ `resolveVersion(config, [slug])`
341
+
342
+ Finds a declared version by its slug.
343
+
344
+ | Parameter | Type | |
345
+ | --- | --- | --- |
346
+ | `config` | `DocPensieveConfig` | Normalised config. |
347
+ | `[slug]` | `string` | Slug to look for. Omitted: the "current" version. |
348
+
349
+ **Returns** `Version` — The requested version.
350
+
351
+ **Throws** `ConfigError` — When the slug does not exist.
352
+
353
+ ### `DocLoader`
354
+
355
+ `class DocLoader`
356
+
357
+ Walks a version folder and produces the list of documents.
358
+
359
+ ### `Compiler`
360
+
361
+ `class Compiler`
362
+
363
+ Compiles an MDX/Markdown source into an HTML fragment.
364
+
365
+ ### `StructuredDataBuilder`
366
+
367
+ `class StructuredDataBuilder`
368
+
369
+ Assembles a schema.org graph for a page.
370
+
371
+ ### `SiteGenerator`
372
+
373
+ `class SiteGenerator`
374
+
375
+ Generates the static site of one or more versions.
376
+
377
+ ### `buildSidebar`
378
+
379
+ `buildSidebar(docs, [toUrl], [options])`
380
+
381
+ Builds the navigation tree of a version.
382
+
383
+ The order is the `DocLoader`'s, which has already sorted: index page first,
384
+ then numeric prefixes, then alphabetical. Nothing is re-sorted here, which
385
+ guarantees that the sidebar follows the reading order of the files exactly.
386
+
387
+ That order has a useful consequence: since `guide/index.md` is loaded
388
+ before `guide/installation.md`, the “guide” category receives its real
389
+ title before a child page creates it with a default one.
390
+
391
+ | Parameter | Type | |
392
+ | --- | --- | --- |
393
+ | `docs` | `import('./loader.js').Doc[]` | Documents in loader order. |
394
+ | `[toUrl]` | `(doc: import('./loader.js').Doc) => string` | Turns a document into a URL. By default, the document's URL as is. |
395
+ | `[options]` | `{ brand?: string }` | `brand` is the name shown in the header: a root entry carrying exactly that title is dropped, since the brand already leads to that page. The same word twice, an inch apart, tells the reader nothing. |
396
+
397
+ **Returns** `SidebarNode[]`
398
+
399
+ ### `buildSidebarFromDescription`
400
+
401
+ `buildSidebarFromDescription(description, docs, [toUrl], [options])`
402
+
403
+ Builds the navigation tree of a version from a description.
404
+
405
+ The description is an array of entries, kept in the order written:
406
+
407
+ - `"guide/installation"` — a page, by its path within the version, as in
408
+ its URL; `"/"` is the home page. Its title becomes the label.
409
+ - `{ "page": "guide/installation", "label": "Install" }` — the same, with a
410
+ label of its own.
411
+ - `{ "label": "Guide", "items": [ … ], "page": "guide" }` — a category,
412
+ clickable when it names a page.
413
+ - `{ "label": "Repository", "href": "https://…" }` — a link outside the site.
414
+ - `{ "auto": "docpensieve" }` — the automatic tree of a folder: a section
415
+ keeps its own menu without listing its pages one by one.
416
+
417
+ A page left out stays published: it is only absent from the menu, which is
418
+ how a page is kept off it.
419
+
420
+ | Parameter | Type | |
421
+ | --- | --- | --- |
422
+ | `description` | `unknown` | Parsed content of the description file. |
423
+ | `docs` | `import('./loader.js').Doc[]` | Documents of the version. |
424
+ | `[toUrl]` | `(doc: import('./loader.js').Doc) => string` | As for `buildSidebar`. |
425
+ | `[options]` | `{ source?: string }` | `source` names the file in messages. |
426
+
427
+ **Returns** `SidebarNode[]`
428
+
429
+ **Throws** `ConfigError` — For a path that names no page, a page listed twice, or an entry of no known kind.
430
+
431
+ ### `collectSectionTitles`
432
+
433
+ `collectSectionTitles(docs)`
434
+
435
+ Collects folder titles, for the breadcrumb.
436
+
437
+ Only folders with an index page have a known title; the others will be
438
+ humanised from their slug by `StructuredDataBuilder`.
439
+
440
+ | Parameter | Type | |
441
+ | --- | --- | --- |
442
+ | `docs` | `import('./loader.js').Doc[]` | |
443
+
444
+ **Returns** `Record<string, string>` — Full folder slug to title.
445
+
446
+ ### `buildFeed`
447
+
448
+ `buildFeed(pages, site)`
449
+
450
+ Builds the RSS feed of the dated pages, newest first.
451
+
452
+ Only a page with a `date` enters it: a documentation page without one is
453
+ reference material, not news, and dating it at build time would announce
454
+ every page again at every build.
455
+
456
+ | Parameter | Type | |
457
+ | --- | --- | --- |
458
+ | `pages` | `PublishedPage[]` | Pages of the current version. |
459
+ | `site` | `{ projectName: string, siteUrl: string, homeUrl: string, feedUrl: string, lang?: string, }` | `homeUrl` and `feedUrl` are absolute. |
460
+
461
+ **Returns** `string`
462
+
463
+ ### `buildRobots`
464
+
465
+ `buildRobots(sitemapUrl)`
466
+
467
+ Builds `robots.txt`, which lets every crawler in and names the sitemap.
468
+
469
+ | Parameter | Type | |
470
+ | --- | --- | --- |
471
+ | `sitemapUrl` | `string` | Absolute address of the sitemap. |
472
+
473
+ **Returns** `string`
474
+
475
+ ### `buildSitemap`
476
+
477
+ `buildSitemap(pages, siteUrl)`
478
+
479
+ Builds `sitemap.xml`.
480
+
481
+ `lastmod` is the page's `modified` date, or failing that its `date`; a page
482
+ that carries neither is listed without one rather than with a made-up date.
483
+
484
+ | Parameter | Type | |
485
+ | --- | --- | --- |
486
+ | `pages` | `PublishedPage[]` | Pages of the versions to list. |
487
+ | `siteUrl` | `string` | Public address of the site: the sitemap only holds absolute addresses. |
488
+
489
+ **Returns** `string`
490
+
491
+ ## `@docpensieve/theme`
492
+
493
+ The theme providers and the engine that composes them.
494
+
495
+ ### `BaseThemeProvider`
496
+
497
+ `class BaseThemeProvider`
498
+
499
+ Base class to extend in order to plug in a CSS framework.
500
+
501
+ A provider generates no HTML: it supplies CSS, variables and a table of
502
+ class aliases. That is what lets a single template render correctly under
503
+ Tailwind as well as under the custom theme.
504
+
505
+ ### `CustomProvider`
506
+
507
+ `class CustomProvider`
508
+
509
+ Custom theme: hand-written CSS, no dependency.
510
+
511
+ ### `DEFAULT_TOKENS`
512
+
513
+ `DEFAULT_TOKENS`
514
+
515
+ Palette and measures of the light theme.
516
+
517
+ Dark mode does not live here: it fits in two blocks of `custom.css`, since
518
+ a flat table of variables cannot express a media query.
519
+
520
+ ### `TailwindProvider`
521
+
522
+ `class TailwindProvider`
523
+
524
+ Tailwind theme: on-demand compilation of the classes actually used.
525
+
526
+ ### `ThemeEngine`
527
+
528
+ `class ThemeEngine`
529
+
530
+ Combines several providers into a single CSS output.
531
+
532
+ ## `@docpensieve/components`
533
+
534
+ The components available in every page.
535
+
536
+ ### `classNames`
537
+
538
+ `classNames(parts)`
539
+
540
+ Joins classes while ignoring falsy values.
541
+
542
+ A minimal equivalent of `clsx`: one more dependency is not worth it for six
543
+ lines.
544
+
545
+ | Parameter | Type | |
546
+ | --- | --- | --- |
547
+ | `parts` | `...unknown` | |
548
+
549
+ **Returns** `string \| undefined` — `undefined` when nothing is left, to avoid a `class=""` in the produced HTML.
550
+
551
+ ### `cls`
552
+
553
+ `cls(slot, modifiers)`
554
+
555
+ Class of a slot, variants included.
556
+
557
+ | Parameter | Type | |
558
+ | --- | --- | --- |
559
+ | `slot` | `string` | Slot name. |
560
+ | `modifiers` | `...unknown` | Variants, each one suffixed as `--variant`. Falsy values are ignored, which allows writing `cls('card', shadow && shadow)`. |
561
+
562
+ **Returns** `string`
563
+
564
+ ### `fallbackClass`
565
+
566
+ `fallbackClass(slot)`
567
+
568
+ Converts a slot name into a fallback class.
569
+
570
+ | Parameter | Type | |
571
+ | --- | --- | --- |
572
+ | `slot` | `string` | |
573
+
574
+ **Returns** `string`
575
+
576
+ ### `getThemeClasses`
577
+
578
+ `getThemeClasses()`
579
+
580
+ @returns \{Record&lt;string, string>\} The current table, for inspection.
581
+
582
+ ### `getThemeFramework`
583
+
584
+ `getThemeFramework()`
585
+
586
+ @returns \{string\} The active framework, or `''` when none was announced.
587
+
588
+ ### `setThemeClasses`
589
+
590
+ `setThemeClasses([classes])`
591
+
592
+ Declares the theme table for the whole compilation.
593
+
594
+ | Parameter | Type | |
595
+ | --- | --- | --- |
596
+ | `[classes]` | `Record<string, string>` | |
597
+
598
+ ### `setThemeFramework`
599
+
600
+ `setThemeFramework([framework])`
601
+
602
+ Declares the framework of the active theme, which `ForTheme` reads.
603
+
604
+ | Parameter | Type | |
605
+ | --- | --- | --- |
606
+ | `[framework]` | `string` | |
607
+
608
+ ### `Card`
609
+
610
+ `Card(props)`
611
+
612
+ Card container.
613
+
614
+ | Parameter | Type | |
615
+ | --- | --- | --- |
616
+ | `props` | `PartProps & { elevated?: boolean, href?: string }` | `elevated` adds a shadow. `href` makes the whole card clickable, rather than a link on the title alone that would leave the rest inert. |
617
+
618
+ ### `CardBody`
619
+
620
+ Documented in `packages/components/src/card.js`.
621
+
622
+ ### `CardFooter`
623
+
624
+ Documented in `packages/components/src/card.js`.
625
+
626
+ ### `CardHeader`
627
+
628
+ Documented in `packages/components/src/card.js`.
629
+
630
+ ### `CardImage`
631
+
632
+ `CardImage(props)`
633
+
634
+ Image at the top of a card.
635
+
636
+ `src` resolves as in Markdown — relative to the page, absolute from the
637
+ version root. The compiler plugins cannot handle it: they work on the
638
+ Markdown tree, before React renders anything. So the component does it
639
+ itself (ADR-006).
640
+
641
+ | Parameter | Type | |
642
+ | --- | --- | --- |
643
+ | `props` | `{ className?: string, style?: object, src?: string, alt?: string, title?: string, srcSet?: string, sizes?: string, loading?: 'lazy' \| 'eager', }` | `alt` defaults to the empty string: without that attribute, a screen reader would announce the file URL. |
644
+
645
+ ### `Column`
646
+
647
+ `Column(props)`
648
+
649
+ Column of a row.
650
+
651
+ | Parameter | Type | |
652
+ | --- | --- | --- |
653
+ | `props` | `{ className?: string, style?: object, children?: any, span?: number }` | `span` is the number of tracks taken out of twelve — `span={6}` for a half, `span={8}` for two thirds. Twelve because twelve divides by two, three, four and six. Without `span`, the columns share the space equally. |
654
+
655
+ **Throws** `DocPensieveError` — Outside a `Columns`, or when the row mixes columns with and without a width.
656
+
657
+ ### `Columns`
658
+
659
+ `Columns(props)`
660
+
661
+ Row of columns.
662
+
663
+ The gap is set through `className` or `style`, with the theme's utilities:
664
+ the grid recomputes the widths by itself.
665
+
666
+ | Parameter | Type | |
667
+ | --- | --- | --- |
668
+ | `props` | `{ className?: string, style?: object, children?: any }` | |
669
+
670
+ ### `FallbackAfter`
671
+
672
+ `FallbackAfter(props)`
673
+
674
+ Content shown after the period.
675
+
676
+ Without a wrapper, for the same reason as \{@link FallbackBefore\}.
677
+
678
+ | Parameter | Type | |
679
+ | --- | --- | --- |
680
+ | `props` | `{ children?: any, end?: string }` | |
681
+
682
+ ### `FallbackBefore`
683
+
684
+ `FallbackBefore(props)`
685
+
686
+ Content shown before the period.
687
+
688
+ No wrapper: a `span` around the author's content would become invalid
689
+ markup as soon as they write a paragraph in it — which happens as soon as a
690
+ blank line separates their text. The content therefore keeps its nature,
691
+ inline or block.
692
+
693
+ | Parameter | Type | |
694
+ | --- | --- | --- |
695
+ | `props` | `{ children?: any, start?: string }` | |
696
+
697
+ ### `TimeTimer`
698
+
699
+ `TimeTimer(props)`
700
+
701
+ Shows its content during a period, with fallbacks before and after.
702
+
703
+ | Parameter | Type | |
704
+ | --- | --- | --- |
705
+ | `props` | `{ date?: string, start?: string, duration?: string, strict?: boolean, children?: any, now?: Date, }` | `now` only exists for tests: without it, the build moment stands. |
706
+
707
+ ### `TOOLTIP_PLACEMENTS`
708
+
709
+ `TOOLTIP_PLACEMENTS`
710
+
711
+ Sides the bubble can sit on.
712
+
713
+ ### `Tooltip`
714
+
715
+ `Tooltip(props)`
716
+
717
+ Term with a tooltip.
718
+
719
+ | Parameter | Type | |
720
+ | --- | --- | --- |
721
+ | `props` | `{ className?: string, style?: object, children?: any, text?: string, placement?: string, }` | `text` is the content of the bubble; the children are the term it explains. |
722
+
723
+ **Throws** `DocPensieveError` — Without text, or with an unknown side.
724
+
725
+ ### `Tree`
726
+
727
+ `Tree(props)`
728
+
729
+ Root of a tree.
730
+
731
+ | Parameter | Type | |
732
+ | --- | --- | --- |
733
+ | `props` | `{ className?: string, style?: object, children?: any }` | |
734
+
735
+ ### `TreeItem`
736
+
737
+ `TreeItem(props)`
738
+
739
+ Entry of a tree.
740
+
741
+ With children, it is a collapsible branch; without, a leaf. The difference
742
+ is read from the writing, with no prop to set.
743
+
744
+ | Parameter | Type | |
745
+ | --- | --- | --- |
746
+ | `props` | `{ className?: string, style?: object, children?: any, label?: any, open?: boolean, }` | `open` expands the branch as soon as the page opens. |
747
+
748
+ **Throws** `DocPensieveError` — Outside a `Tree`, or without a label.
749
+
750
+ ### `ScrollToTop`
751
+
752
+ `ScrollToTop(props)`
753
+
754
+ Back-to-top button.
755
+
756
+ | Parameter | Type | |
757
+ | --- | --- | --- |
758
+ | `props` | `{ className?: string, style?: object, children?: any, label?: string, }` | `label` is read by screen readers. The children replace the arrow with whatever you want. |
759
+
760
+ ### `SKILL_SHAPES`
761
+
762
+ `SKILL_SHAPES`
763
+
764
+ Shapes accepted by the gauge.
765
+
766
+ ### `Skill`
767
+
768
+ `Skill(props)`
769
+
770
+ Named gauge, from 0 to 100.
771
+
772
+ | Parameter | Type | |
773
+ | --- | --- | --- |
774
+ | `props` | `{ className?: string, style?: object, children?: any, name?: any, level?: number, showValue?: boolean, shape?: string, icon?: any, color?: string, label?: string, }` | `children` stands as a comment under the gauge. `showValue` hides the numeric percentage without touching what the gauge announces. `shape` picks between the bar and the circle. `icon` goes before the name — a `LogoIcon` fits there. `color` tints the fill: any CSS colour, the accent colour by default. `label` names the gauge for screen readers when `name` is not text. |
775
+
776
+ **Throws** `DocPensieveError` — Without a name, outside 0–100, or with an unknown shape.
777
+
778
+ ### `LogoIcon`
779
+
780
+ `LogoIcon(props)`
781
+
782
+ Project SVG icon, inlined in the page.
783
+
784
+ | Parameter | Type | |
785
+ | --- | --- | --- |
786
+ | `props` | `{ className?: string, style?: object, src?: string, label?: string, size?: string, }` | `label` describes the icon; without it the icon is treated as decorative and hidden from screen readers — which is right when nearby text already says the same thing. `size` accepts any CSS length. |
787
+
788
+ **Throws** `DocPensieveError` — Without `src`, or when the file cannot be read.
789
+
790
+ ### `ForTheme`
791
+
792
+ `ForTheme(props)`
793
+
794
+ Renders its children only when the site's theme is `framework`.
795
+
796
+ | Parameter | Type | |
797
+ | --- | --- | --- |
798
+ | `props` | `{ framework?: string, children?: any }` | |
799
+
800
+ **Returns** `any`
801
+
802
+ **Throws** `DocPensieveError` — For a framework the configuration does not know, or when no theme was announced.
803
+
804
+ ### `componentsCss`
805
+
806
+ `componentsCss()`
807
+
808
+ Reads the default look of the components.
809
+
810
+ It is concatenated with the theme's by the caller: a provider that
811
+ redefines a slot replaces the `dp-*` class with its own, and these rules
812
+ then stop applying by themselves.
813
+
814
+ **Returns** `Promise<string>` — CSS, trimmed.
815
+
816
+ **Throws** `DocPensieveError` — When the stylesheet is missing.
817
+
818
+ ### `getSiteContext`
819
+
820
+ `getSiteContext()`
821
+
822
+ @returns \{SiteContext\} The current context.
823
+
824
+ ### `resolveFile`
825
+
826
+ `resolveFile(target)`
827
+
828
+ Resolves a target into a file path, for a resource read at build time.
829
+
830
+ Same landmarks as for a URL, mapped to the disk: a relative target starts
831
+ from the page's file, an absolute one from the version folder. Nothing can
832
+ leave that folder — a page does not read the rest of the machine.
833
+
834
+ | Parameter | Type | |
835
+ | --- | --- | --- |
836
+ | `target` | `string` | |
837
+
838
+ **Returns** `string` — Absolute path, inside the source folder.
839
+
840
+ **Throws** `Error` — When the context is missing or the target escapes it.
841
+
842
+ ### `resolveUrl`
843
+
844
+ `resolveUrl(target)`
845
+
846
+ Resolves a target written by an author into a site URL.
847
+
848
+ Same rules as for Markdown content: a relative target resolves against the
849
+ page's folder, an absolute target starts from the version root.
850
+
851
+ | Parameter | Type | |
852
+ | --- | --- | --- |
853
+ | `target` | `string \| undefined` | |
854
+
855
+ **Returns** `string \| undefined` — The resolved target, or as is when external.
856
+
857
+ ### `setSiteContext`
858
+
859
+ `setSiteContext([page])`
860
+
861
+ Declares the page being rendered.
862
+
863
+ Set by the generator before every page, like the class table.
864
+
865
+ | Parameter | Type | |
866
+ | --- | --- | --- |
867
+ | `[page]` | `Partial<SiteContext>` | |
868
+
869
+ ### `builtinComponents`
870
+
871
+ `builtinComponents`
872
+
873
+ Components shipped with DocPensieve.
874
+
875
+ ### `createRegistry`
876
+
877
+ `createRegistry([userComponents])`
878
+
879
+ Builds the component table passed to the MDX compiler.
880
+
881
+ | Parameter | Type | |
882
+ | --- | --- | --- |
883
+ | `[userComponents]` | `Record<string, Function>` | Project components, which override the built-in components of the same name. |
884
+
885
+ **Returns** `Record<string, Function>` — Table ready for @mdx-js/mdx.
886
+
887
+ ### `listComponentNames`
888
+
889
+ `listComponentNames(registry)`
890
+
891
+ Lists the available component names — useful for a readable error message
892
+ when an `.mdx` references an unknown component.
893
+
894
+ | Parameter | Type | |
895
+ | --- | --- | --- |
896
+ | `registry` | `Record<string, Function>` | |
897
+
898
+ **Returns** `string[]` — Names sorted alphabetically.
899
+
900
+ ## `docpensieve`
901
+
902
+ The commands, callable from a script as well as from the terminal.
903
+
904
+ ### `build`
905
+
906
+ `build(versionSlug, [options])`
907
+
908
+ | Parameter | Type | |
909
+ | --- | --- | --- |
910
+ | `versionSlug` | `string \| undefined` | Version to generate, or all of them when omitted. |
911
+ | `[options]` | `{ out?: string, cwd?: string }` | |
912
+
913
+ **Returns** `Promise<void>`
914
+
915
+ ### `check`
916
+
917
+ `check([options])`
918
+
919
+ Reads the produced site back and reports what is wrong.
920
+
921
+ | Parameter | Type | |
922
+ | --- | --- | --- |
923
+ | `[options]` | `{ dir?: string, cwd?: string }` | |
924
+
925
+ **Returns** `Promise<{ root: string, pages: number, faults: Fault[] }>`
926
+
927
+ **Throws** `DocPensieveError` — When the folder does not exist, or when something is left to fix — the exit code is then that of an expected error, which is enough to fail a continuous integration run.
928
+
929
+ ### `verifyLinks`
930
+
931
+ `verifyLinks(root, [baseUrl])`
932
+
933
+ Checks the internal links of a generated site.
934
+
935
+ Exported apart from the command: it reads no configuration and addresses no
936
+ one, which makes it usable elsewhere and testable on its own.
937
+
938
+ | Parameter | Type | |
939
+ | --- | --- | --- |
940
+ | `root` | `string` | Folder of the produced site. |
941
+ | `[baseUrl]` | `string` | Deployment prefix, slashes included. |
942
+
943
+ **Returns** `Promise<{ pages: number, faults: Fault[] }>`
944
+
945
+ ### `verifyMarkup`
946
+
947
+ `verifyMarkup(root)`
948
+
949
+ Checks the markup of a generated site.
950
+
951
+ | Parameter | Type | |
952
+ | --- | --- | --- |
953
+ | `root` | `string` | Folder of the produced site. |
954
+
955
+ **Returns** `Promise<{ pages: number, faults: Fault[] }>`
956
+
957
+ ### `dev`
958
+
959
+ `dev([options])`
960
+
961
+ | Parameter | Type | |
962
+ | --- | --- | --- |
963
+ | `[options]` | `{ port?: number, cwd?: string }` | |
964
+
965
+ **Returns** `Promise<{ server: import('node:http').Server, watcher: import('chokidar').FSWatcher, port: number, url: string, close: () => Promise<void>, }>`
966
+
967
+ ### `init`
968
+
969
+ `init([dir], [options])`
970
+
971
+ Sets up a documentation project.
972
+
973
+ | Parameter | Type | |
974
+ | --- | --- | --- |
975
+ | `[dir]` | `string` | Target folder, created if needed. |
976
+ | `[options]` | `{ name?: string, theme?: string, siteUrl?: string, version?: string, yes?: boolean, force?: boolean, minimal?: boolean, }` | `minimal` leaves DocPensieve's documentation out of the site. |
977
+
978
+ **Returns** `Promise<{ dir: string, theme: string, docs: boolean }>`
979
+
980
+ **Throws** `DocPensieveError` — Unknown framework, project already initialised, or documentation to install missing.
981
+
982
+ ### `serve`
983
+
984
+ `serve([options])`
985
+
986
+ | Parameter | Type | |
987
+ | --- | --- | --- |
988
+ | `[options]` | `{ port?: number, dir?: string, cwd?: string }` | |
989
+
990
+ **Returns** `Promise<{ server: import('node:http').Server, port: number, url: string }>`
991
+
992
+ **Throws** `DocPensieveError` — When the folder to serve does not exist.
993
+
994
+ ### `createStaticServer`
995
+
996
+ `createStaticServer(options)`
997
+
998
+ Creates a static file server.
999
+
1000
+ | Parameter | Type | |
1001
+ | --- | --- | --- |
1002
+ | `options` | `{ root: string, basePath?: string, inject?: string \| null, onReload?: (send: () => void) => void, }` | `basePath` is the prefix under which the site is mounted: it must reflect the configuration's `baseUrl`, otherwise the links of the pages do not resolve locally. `inject` is an HTML fragment inserted before `</body>` — the development server uses it for its reload script, which leaves the generated output intact. |
1003
+
1004
+ **Returns** `import('node:http').Server`
1005
+
1006
+ ### `listen`
1007
+
1008
+ `listen(server, port, [attempts])`
1009
+
1010
+ Starts listening, looking for a free port if needed.
1011
+
1012
+ | Parameter | Type | |
1013
+ | --- | --- | --- |
1014
+ | `server` | `import('node:http').Server` | |
1015
+ | `port` | `number` | Desired port. |
1016
+ | `[attempts]` | `number` | Number of ports tried from `port` on. |
1017
+
1018
+ **Returns** `Promise<number>` — The port actually used.
1019
+
1020
+ **Throws** `DocPensieveError` — When no port is free in the range.
1021
+
1022
+ ### `resolveRequestPath`
1023
+
1024
+ `resolveRequestPath(pathname, root)`
1025
+
1026
+ Resolves a request URL into a file path, without leaving the root.
1027
+
1028
+ | Parameter | Type | |
1029
+ | --- | --- | --- |
1030
+ | `pathname` | `string` | Request path, `basePath` already removed. |
1031
+ | `root` | `string` | Served folder. |
1032
+
1033
+ **Returns** `string \| null` — Absolute path, or `null` when the target escapes `root`.