svelte-docsmith 0.12.2 → 0.13.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/README.md +40 -11
- package/dist/buildtime/archive.d.ts +18 -0
- package/dist/buildtime/archive.js +61 -1
- package/dist/buildtime/archives.d.ts +3 -0
- package/dist/buildtime/archives.js +3 -0
- package/dist/buildtime/cli/archive-version.d.ts +3 -0
- package/dist/buildtime/cli/archive-version.js +30 -2
- package/dist/buildtime/cli/run.js +3 -0
- package/dist/buildtime/git.d.ts +13 -6
- package/dist/buildtime/git.js +31 -6
- package/dist/buildtime/markdown-source.d.ts +9 -0
- package/dist/buildtime/markdown-source.js +22 -0
- package/dist/buildtime/vite/index.d.ts +4 -0
- package/dist/buildtime/vite/index.js +4 -1
- package/dist/core/content.d.ts +5 -3
- package/dist/core/version.d.ts +24 -2
- package/dist/core/version.js +3 -0
- package/dist/index.js +6 -4
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -15,8 +15,17 @@ Write a markdown file under `src/routes/docs/` and you get a styled page with
|
|
|
15
15
|
syntax highlighting, heading anchors, a sidebar derived from your content, and a
|
|
16
16
|
live table of contents. No per-page wiring, no content collection to configure.
|
|
17
17
|
|
|
18
|
-
> **Status: pre-1.0.** Published to npm and usable today.
|
|
19
|
-
>
|
|
18
|
+
> **Status: pre-1.0.** Published to npm and usable today. Minor releases may still
|
|
19
|
+
> include breaking changes until v1.0.
|
|
20
|
+
>
|
|
21
|
+
> **What 1.0 will lock.** Authoring components, `DocsShell`, `ErrorPage`,
|
|
22
|
+
> `defineConfig`, the preprocessor, the Vite plugin, the sitemap / llms / feed
|
|
23
|
+
> generators, the search engine, and the theming contract — ordinary semver,
|
|
24
|
+
> breaking changes ride a major.
|
|
25
|
+
>
|
|
26
|
+
> **What stays experimental.** Versioning: `DocsVersions`, `currentOnly`, the
|
|
27
|
+
> archive marker, and the `archive-version` command. They may still change in a
|
|
28
|
+
> minor until authors have used them for real.
|
|
20
29
|
|
|
21
30
|
## Install
|
|
22
31
|
|
|
@@ -166,6 +175,20 @@ plugin you already added:
|
|
|
166
175
|
Graph / Twitter tags for every page from its frontmatter, no per-page wiring.
|
|
167
176
|
- **Error pages.** `ErrorPage` gives a styled 404 that keeps the site chrome;
|
|
168
177
|
drop it into a SvelteKit `+error.svelte`.
|
|
178
|
+
- **Versioned docs.** Declare `versions` on the Vite plugin, freeze a release
|
|
179
|
+
with `npx svelte-docsmith archive-version <id>`, and pass the generated
|
|
180
|
+
manifest to `DocsShell`. Scope sitemap / llms endpoints to the current
|
|
181
|
+
version with `currentOnly`.
|
|
182
|
+
- **Changelog.** Point the plugin at your `CHANGELOG.md`; import the parsed
|
|
183
|
+
releases from `svelte-docsmith/changelog`, render them with `Changelog`, and
|
|
184
|
+
wire `generateFeed` into an Atom endpoint.
|
|
185
|
+
- **Mermaid.** A mermaid code fence is rendered client-side (optional `mermaid`
|
|
186
|
+
peer dependency, loaded only on pages that need it).
|
|
187
|
+
- **Landing sections.** `Hero`, `FeatureGrid`, `Feature`, `CTA`, and `Action`
|
|
188
|
+
for the marketing page in front of your docs.
|
|
189
|
+
- **Generators.** Framework-agnostic helpers for `sitemap.xml`, `llms.txt` /
|
|
190
|
+
`llms-full.txt`, and the changelog Atom feed — drop them into `+server.ts`
|
|
191
|
+
routes over the generated indexes.
|
|
169
192
|
- **Components.** `Callout`, `Tabs`, `Steps`, `Card`, `Accordion`, `Badge`,
|
|
170
193
|
`Kbd`, `FileTree`, `PropsTable`, and more, authored right inside markdown.
|
|
171
194
|
- Heading anchors, a scroll-spy table of contents, and one-click copy on every
|
|
@@ -187,15 +210,21 @@ override the tokens yourself.
|
|
|
187
210
|
|
|
188
211
|
## What's exported
|
|
189
212
|
|
|
190
|
-
| Entry point | What it is
|
|
191
|
-
| ------------------------------ |
|
|
192
|
-
| `svelte-docsmith` |
|
|
193
|
-
| `svelte-docsmith/preprocess` | `docsmith()`, the mdsvex/Shiki pipeline (Node, config time)
|
|
194
|
-
| `svelte-docsmith/vite` | `docsmith()`, the content
|
|
195
|
-
| `svelte-docsmith/content` | `docs`, the generated sidebar content index
|
|
196
|
-
| `svelte-docsmith/search` | `docs`, the generated full-text search index (lazy-load it)
|
|
197
|
-
| `svelte-docsmith/
|
|
198
|
-
| `svelte-docsmith/
|
|
213
|
+
| Entry point | What it is |
|
|
214
|
+
| ------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
215
|
+
| `svelte-docsmith` | Components (`DocsShell`, `Changelog`, landing sections, `LiveExample`, `Callout`, …), `defineConfig`, `createSearchEngine`, `generateSitemap` / `generateLlmsTxt` / `generateLlmsFullTxt` / `generateFeed`, `currentOnly`, and the types |
|
|
216
|
+
| `svelte-docsmith/preprocess` | `docsmith()`, the mdsvex/Shiki pipeline (Node, config time) |
|
|
217
|
+
| `svelte-docsmith/vite` | `docsmith()`, the content / search / llms / changelog indexes and `?source` transform (Node, build) |
|
|
218
|
+
| `svelte-docsmith/content` | `docs` and `versions`, the generated sidebar content index and version manifest |
|
|
219
|
+
| `svelte-docsmith/search` | `docs`, the generated full-text search index (lazy-load it) |
|
|
220
|
+
| `svelte-docsmith/llms` | `docs`, the generated LLM content index (for `llms.txt` / `llms-full.txt` routes) |
|
|
221
|
+
| `svelte-docsmith/changelog` | `releases`, the generated changelog index (parsed from `CHANGELOG.md`) |
|
|
222
|
+
| `svelte-docsmith/mermaid` | the Mermaid diagram component (lazy-loaded by the preprocessor when a mermaid fence is present) |
|
|
223
|
+
| `svelte-docsmith/theme.css` | the base style contract |
|
|
224
|
+
| `svelte-docsmith/themes/*.css` | the eleven theme presets |
|
|
225
|
+
|
|
226
|
+
The package also ships a CLI binary: `npx svelte-docsmith archive-version <id>`
|
|
227
|
+
freezes the current docs into a versioned archive.
|
|
199
228
|
|
|
200
229
|
The vendored shadcn primitives and internal helpers (the TOC engine, clipboard
|
|
201
230
|
utility, markdown renderer map) are **not** part of the public API; they can
|
|
@@ -29,3 +29,21 @@ export declare function rewriteDocsLinks(text: string, options: {
|
|
|
29
29
|
* existing `lastUpdated` and any page without frontmatter alone.
|
|
30
30
|
*/
|
|
31
31
|
export declare function freezeLastUpdated(text: string, date: string | undefined): string;
|
|
32
|
+
/**
|
|
33
|
+
* The specifiers a page's `<script>` imports from outside the freeze boundary,
|
|
34
|
+
* deduplicated in source order. `pageDir` is the page's directory relative to
|
|
35
|
+
* the docs root, which is what its relative imports resolve against.
|
|
36
|
+
*
|
|
37
|
+
* Archiving copies the docs root and nothing else, so anything reached from
|
|
38
|
+
* outside it keeps resolving to current code: a live example on an archived
|
|
39
|
+
* page demonstrates the current library rather than the version the page
|
|
40
|
+
* documents, with a green build and nothing said. Hence `$lib`, bare npm
|
|
41
|
+
* specifiers and relative paths that climb out all count, while a relative
|
|
42
|
+
* import landing inside the docs root is frozen along with the page.
|
|
43
|
+
*
|
|
44
|
+
* `svelte-docsmith` itself is never reported. An archived page importing the
|
|
45
|
+
* authoring components is the expected shape, and those are covered by the
|
|
46
|
+
* stability promise rather than by this notice. See
|
|
47
|
+
* `docs/adr/0005-an-archive-freezes-content-not-dependencies.md`.
|
|
48
|
+
*/
|
|
49
|
+
export declare function boundaryCrossings(source: string, pageDir: string): string[];
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* CLI is a thin wrapper over them. See `docs/adr/0002-archives-are-rewritten-source-copies.md`.
|
|
9
9
|
*/
|
|
10
10
|
import { atBoundary, firstSegmentUnder } from '../utils/url.js';
|
|
11
|
-
import { outsideCodeFences, withFrontmatter } from './markdown-source.js';
|
|
11
|
+
import { outsideCodeFences, scriptBlocks, withFrontmatter } from './markdown-source.js';
|
|
12
12
|
/** Route files at the docs root that an archive nested inside it already inherits. */
|
|
13
13
|
export function isInheritedRouteFile(name) {
|
|
14
14
|
return /^\+(layout|error)\./.test(name);
|
|
@@ -50,3 +50,63 @@ export function freezeLastUpdated(text, date) {
|
|
|
50
50
|
return text;
|
|
51
51
|
return withFrontmatter(text, (front) => /^lastUpdated:/m.test(front) ? front : `${front}\nlastUpdated: '${date}'`);
|
|
52
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* An import's specifier, static or dynamic. The clause between `import` and
|
|
55
|
+
* `from` may not hold a quote or a paren, so the scan cannot run past a
|
|
56
|
+
* side-effect import to borrow a later `from`, and `import.meta.glob('./x')`
|
|
57
|
+
* matches nothing.
|
|
58
|
+
*/
|
|
59
|
+
const IMPORT = /\bimport\s*\(?\s*(?:[^'"()]*?\bfrom\s*)?['"]([^'"]+)['"]/g;
|
|
60
|
+
/** The package an archived page is expected to import, and its subpaths. */
|
|
61
|
+
const LIBRARY = 'svelte-docsmith';
|
|
62
|
+
/**
|
|
63
|
+
* Whether a relative specifier climbs out of the docs root when resolved from a
|
|
64
|
+
* page `depth` directories inside it. Counting segments rather than resolving
|
|
65
|
+
* real paths keeps the rule pure, and the docs root is the only boundary that
|
|
66
|
+
* matters: where under it a surviving import lands is the archive's business.
|
|
67
|
+
*/
|
|
68
|
+
function escapesRoot(specifier, depth) {
|
|
69
|
+
let level = depth;
|
|
70
|
+
for (const segment of specifier.split('/')) {
|
|
71
|
+
if (segment === '..')
|
|
72
|
+
level--;
|
|
73
|
+
else if (segment !== '.' && segment !== '')
|
|
74
|
+
level++;
|
|
75
|
+
if (level < 0)
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* The specifiers a page's `<script>` imports from outside the freeze boundary,
|
|
82
|
+
* deduplicated in source order. `pageDir` is the page's directory relative to
|
|
83
|
+
* the docs root, which is what its relative imports resolve against.
|
|
84
|
+
*
|
|
85
|
+
* Archiving copies the docs root and nothing else, so anything reached from
|
|
86
|
+
* outside it keeps resolving to current code: a live example on an archived
|
|
87
|
+
* page demonstrates the current library rather than the version the page
|
|
88
|
+
* documents, with a green build and nothing said. Hence `$lib`, bare npm
|
|
89
|
+
* specifiers and relative paths that climb out all count, while a relative
|
|
90
|
+
* import landing inside the docs root is frozen along with the page.
|
|
91
|
+
*
|
|
92
|
+
* `svelte-docsmith` itself is never reported. An archived page importing the
|
|
93
|
+
* authoring components is the expected shape, and those are covered by the
|
|
94
|
+
* stability promise rather than by this notice. See
|
|
95
|
+
* `docs/adr/0005-an-archive-freezes-content-not-dependencies.md`.
|
|
96
|
+
*/
|
|
97
|
+
export function boundaryCrossings(source, pageDir) {
|
|
98
|
+
const depth = pageDir.split('/').filter(Boolean).length;
|
|
99
|
+
const found = new Set();
|
|
100
|
+
for (const block of scriptBlocks(source)) {
|
|
101
|
+
for (const [, specifier] of block.matchAll(IMPORT)) {
|
|
102
|
+
if (specifier === LIBRARY || specifier.startsWith(`${LIBRARY}/`))
|
|
103
|
+
continue;
|
|
104
|
+
// Only a package name can start with something other than a dot, and no
|
|
105
|
+
// package name starts with one, so this is the whole relative/bare split.
|
|
106
|
+
if (specifier.startsWith('.') && !escapesRoot(specifier, depth))
|
|
107
|
+
continue;
|
|
108
|
+
found.add(specifier);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return [...found];
|
|
112
|
+
}
|
|
@@ -6,6 +6,9 @@ import type { ArchivesOnDisk } from '../core/version.js';
|
|
|
6
6
|
* are otherwise indistinguishable, since a page is assigned to a version by its
|
|
7
7
|
* first directory segment. See
|
|
8
8
|
* `docs/adr/0003-the-archive-marker-defines-an-archive.md`.
|
|
9
|
+
*
|
|
10
|
+
* @experimental Outside the 1.0 stability promise. Name and role may change in
|
|
11
|
+
* a minor until authors have used versioning for real.
|
|
9
12
|
*/
|
|
10
13
|
export declare const ARCHIVE_MARKER = ".docsmith-archive";
|
|
11
14
|
/** The text written into a new archive's marker file. */
|
|
@@ -16,6 +16,9 @@ import path from 'node:path';
|
|
|
16
16
|
* are otherwise indistinguishable, since a page is assigned to a version by its
|
|
17
17
|
* first directory segment. See
|
|
18
18
|
* `docs/adr/0003-the-archive-marker-defines-an-archive.md`.
|
|
19
|
+
*
|
|
20
|
+
* @experimental Outside the 1.0 stability promise. Name and role may change in
|
|
21
|
+
* a minor until authors have used versioning for real.
|
|
19
22
|
*/
|
|
20
23
|
export const ARCHIVE_MARKER = '.docsmith-archive';
|
|
21
24
|
/** The text written into a new archive's marker file. */
|
|
@@ -14,5 +14,8 @@ export type ArchiveVersionOptions = {
|
|
|
14
14
|
* Copy the docs root into `<content>/<id>/`, mark it as an archive, and rewrite
|
|
15
15
|
* each copied page so it stays inside the archive and keeps its real
|
|
16
16
|
* last-updated date. Returns the number of pages archived.
|
|
17
|
+
*
|
|
18
|
+
* @experimental Outside the 1.0 stability promise. May change in a minor until
|
|
19
|
+
* authors have used versioning for real.
|
|
17
20
|
*/
|
|
18
21
|
export declare function archiveVersion(options: ArchiveVersionOptions, log: (line: string) => void): number;
|
|
@@ -3,15 +3,23 @@
|
|
|
3
3
|
* archived version folder so they keep serving the release they document while
|
|
4
4
|
* the docs root goes on being edited.
|
|
5
5
|
*
|
|
6
|
+
* Freezes content, not dependencies: the prose, samples and URLs are that
|
|
7
|
+
* version's, while anything a page imports keeps resolving to whatever the app
|
|
8
|
+
* currently has installed. See
|
|
9
|
+
* `docs/adr/0005-an-archive-freezes-content-not-dependencies.md`.
|
|
10
|
+
*
|
|
6
11
|
* The pure text transforms live in `../archive.js`; this is the filesystem work
|
|
7
12
|
* around them. It takes its working directory and its output sink rather than
|
|
8
13
|
* reading `process.cwd()` and calling `console.log`, so the whole command runs
|
|
9
14
|
* in-process under test. See `docs/adr/0002-archives-are-rewritten-source-copies.md`.
|
|
15
|
+
*
|
|
16
|
+
* @experimental Outside the 1.0 stability promise. Flags and behaviour may
|
|
17
|
+
* change in a minor until authors have used versioning for real.
|
|
10
18
|
*/
|
|
11
19
|
import fs from 'node:fs';
|
|
12
20
|
import path from 'node:path';
|
|
13
21
|
import { assertValidVersionId } from '../../core/version.js';
|
|
14
|
-
import { freezeLastUpdated, isInheritedRouteFile, rewriteDocsLinks } from '../archive.js';
|
|
22
|
+
import { boundaryCrossings, freezeLastUpdated, isInheritedRouteFile, rewriteDocsLinks } from '../archive.js';
|
|
15
23
|
import { ARCHIVE_MARKER, discoverArchives, markerContents } from '../archives.js';
|
|
16
24
|
import { commitDates } from '../git.js';
|
|
17
25
|
import { docsBaseFrom } from '../paths.js';
|
|
@@ -21,6 +29,9 @@ import { CliError } from './error.js';
|
|
|
21
29
|
* Copy the docs root into `<content>/<id>/`, mark it as an archive, and rewrite
|
|
22
30
|
* each copied page so it stays inside the archive and keeps its real
|
|
23
31
|
* last-updated date. Returns the number of pages archived.
|
|
32
|
+
*
|
|
33
|
+
* @experimental Outside the 1.0 stability promise. May change in a minor until
|
|
34
|
+
* authors have used versioning for real.
|
|
24
35
|
*/
|
|
25
36
|
export function archiveVersion(options, log) {
|
|
26
37
|
const cwd = options.cwd ?? process.cwd();
|
|
@@ -84,17 +95,23 @@ export function archiveVersion(options, log) {
|
|
|
84
95
|
// be read: an archive is written once and never edited again, so a page that
|
|
85
96
|
// misses its date here keeps the wrong one for good.
|
|
86
97
|
const dates = commitDates(contentDir, (reason) => {
|
|
87
|
-
log(`\n!
|
|
98
|
+
log(`\n! Skipping git-derived page dates: ${reason}`);
|
|
88
99
|
log(' Archived pages will keep no last-updated date.\n');
|
|
89
100
|
});
|
|
90
101
|
copyCurrent(contentDir, toDir);
|
|
91
102
|
fs.writeFileSync(path.join(toDir, ARCHIVE_MARKER), markerContents(id));
|
|
92
103
|
let pages = 0;
|
|
104
|
+
/** One `path: specifiers` line per page that imports across the freeze boundary. */
|
|
105
|
+
const crossings = [];
|
|
93
106
|
for (const { file, source } of eachCopiedFile()) {
|
|
94
107
|
if (!isPageFile(path.basename(file)))
|
|
95
108
|
continue;
|
|
96
109
|
pages++;
|
|
97
110
|
const text = fs.readFileSync(file, 'utf-8');
|
|
111
|
+
const pageDir = path.relative(toDir, path.dirname(file)).split(path.sep).join('/');
|
|
112
|
+
const crossed = boundaryCrossings(text, pageDir);
|
|
113
|
+
if (crossed.length)
|
|
114
|
+
crossings.push(` ${rel(file)}: ${crossed.join(', ')}`);
|
|
98
115
|
fs.writeFileSync(file, freezeLastUpdated(rewriteDocsLinks(text, { docsBase, versionId: id, archivedIds }), dates.get(source)));
|
|
99
116
|
}
|
|
100
117
|
log(`\n✓ Archived the current docs into ${rel(toDir)} (${pages} pages)\n`);
|
|
@@ -102,6 +119,17 @@ export function archiveVersion(options, log) {
|
|
|
102
119
|
// Only claim the dates were kept when the walk actually produced some.
|
|
103
120
|
if (dates.size)
|
|
104
121
|
log('Each page kept its real last-updated date.');
|
|
122
|
+
// Informational: the archive is correct as content, and there is nothing to
|
|
123
|
+
// fix here. Said out loud because the alternative is a green build hiding a
|
|
124
|
+
// v1 page that demos v2, which nothing downstream can notice.
|
|
125
|
+
if (crossings.length) {
|
|
126
|
+
const count = crossings.length === 1 ? '1 page' : `${crossings.length} pages`;
|
|
127
|
+
log(`\n! ${count} import across the freeze boundary:`);
|
|
128
|
+
crossings.sort().forEach(log);
|
|
129
|
+
log(' Archiving copies the docs root, not what it imports, so these keep');
|
|
130
|
+
log(' resolving to current code. Their examples will demonstrate the');
|
|
131
|
+
log(' current library rather than the version this archive documents.\n');
|
|
132
|
+
}
|
|
105
133
|
log('Review the diff, then update docsmith({ versions }) so the archive');
|
|
106
134
|
log('is served:\n');
|
|
107
135
|
log(' versions: {');
|
|
@@ -7,6 +7,9 @@
|
|
|
7
7
|
* message and an exit code. Keeping the process boundary out here means the
|
|
8
8
|
* command is typechecked, and testable in-process against a temporary directory
|
|
9
9
|
* rather than by spawning node and parsing stdout.
|
|
10
|
+
*
|
|
11
|
+
* @experimental `archive-version` sits outside the 1.0 stability promise and
|
|
12
|
+
* may change in a minor until authors have used versioning for real.
|
|
10
13
|
*/
|
|
11
14
|
import { archiveVersion } from './archive-version.js';
|
|
12
15
|
import { CliError } from './error.js';
|
package/dist/buildtime/git.d.ts
CHANGED
|
@@ -14,12 +14,19 @@
|
|
|
14
14
|
* all-or-nothing: a truncated read would date some pages and not others, which
|
|
15
15
|
* looks like real data and is not.
|
|
16
16
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
17
|
+
* A shallow clone also yields no dates. Its single commit introduces every
|
|
18
|
+
* tracked file, so a walk would stamp every page with the same day — silent,
|
|
19
|
+
* plausible, and wrong for both page footers and sitemap `<lastmod>`. Omitting
|
|
20
|
+
* the date is legitimate; a uniform wrong date is not. Callers that need real
|
|
21
|
+
* dates should build from a full clone (`fetch-depth: 0` in CI, unshallow on
|
|
22
|
+
* the host).
|
|
23
|
+
*
|
|
24
|
+
* `onFail` fires for a truncated read or a shallow repository: those are the
|
|
25
|
+
* cases that would otherwise produce dates that look real and are not. A
|
|
26
|
+
* directory outside a repository, a missing directory, or a machine without git
|
|
27
|
+
* all yield no dates quietly, which every caller already handles. Reporting is
|
|
28
|
+
* the caller's to do, which is why this takes a callback rather than writing to
|
|
29
|
+
* the console itself.
|
|
23
30
|
*/
|
|
24
31
|
export declare function commitDates(dir: string, onFail?: (reason: string) => void,
|
|
25
32
|
/**
|
package/dist/buildtime/git.js
CHANGED
|
@@ -28,12 +28,19 @@ import path from 'node:path';
|
|
|
28
28
|
* all-or-nothing: a truncated read would date some pages and not others, which
|
|
29
29
|
* looks like real data and is not.
|
|
30
30
|
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
31
|
+
* A shallow clone also yields no dates. Its single commit introduces every
|
|
32
|
+
* tracked file, so a walk would stamp every page with the same day — silent,
|
|
33
|
+
* plausible, and wrong for both page footers and sitemap `<lastmod>`. Omitting
|
|
34
|
+
* the date is legitimate; a uniform wrong date is not. Callers that need real
|
|
35
|
+
* dates should build from a full clone (`fetch-depth: 0` in CI, unshallow on
|
|
36
|
+
* the host).
|
|
37
|
+
*
|
|
38
|
+
* `onFail` fires for a truncated read or a shallow repository: those are the
|
|
39
|
+
* cases that would otherwise produce dates that look real and are not. A
|
|
40
|
+
* directory outside a repository, a missing directory, or a machine without git
|
|
41
|
+
* all yield no dates quietly, which every caller already handles. Reporting is
|
|
42
|
+
* the caller's to do, which is why this takes a callback rather than writing to
|
|
43
|
+
* the console itself.
|
|
37
44
|
*/
|
|
38
45
|
export function commitDates(dir, onFail,
|
|
39
46
|
/**
|
|
@@ -43,6 +50,13 @@ export function commitDates(dir, onFail,
|
|
|
43
50
|
*/
|
|
44
51
|
maxBuffer = 256 * 1024 * 1024) {
|
|
45
52
|
const dates = new Map();
|
|
53
|
+
// One cheap probe before the walk. On a shallow clone the walk would "work"
|
|
54
|
+
// and return one day for every file — worse than failing, so refuse first.
|
|
55
|
+
if (isShallowRepository(dir)) {
|
|
56
|
+
onFail?.('shallow clone: git history is incomplete, so commit dates would be wrong. ' +
|
|
57
|
+
'Build from a full clone (e.g. actions/checkout fetch-depth: 0), or set lastUpdated in frontmatter.');
|
|
58
|
+
return dates;
|
|
59
|
+
}
|
|
46
60
|
const res = spawnSync('git', ['log', '--format=%cs', '--name-only', '--relative', '--no-renames', '--', '.'],
|
|
47
61
|
// The 1 MB default would truncate rather than throw on a large history,
|
|
48
62
|
// which is why the cap is raised and the result checked below.
|
|
@@ -71,6 +85,17 @@ maxBuffer = 256 * 1024 * 1024) {
|
|
|
71
85
|
}
|
|
72
86
|
return dates;
|
|
73
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* Whether `dir` sits in a shallow clone. Outside a repository, or when git is
|
|
90
|
+
* missing, returns false so the walk's own failure path still owns that case.
|
|
91
|
+
*/
|
|
92
|
+
function isShallowRepository(dir) {
|
|
93
|
+
const res = spawnSync('git', ['rev-parse', '--is-shallow-repository'], {
|
|
94
|
+
cwd: dir,
|
|
95
|
+
encoding: 'utf-8'
|
|
96
|
+
});
|
|
97
|
+
return res.status === 0 && res.stdout.trim() === 'true';
|
|
98
|
+
}
|
|
74
99
|
/**
|
|
75
100
|
* Release dates keyed by version, read from the commit that introduced each
|
|
76
101
|
* `## <version>` heading in a changelog. Changesets does not write dates, and a
|
|
@@ -29,3 +29,12 @@ export declare function withFrontmatter(source: string, transform: (frontmatter:
|
|
|
29
29
|
export declare function outsideCodeFences(text: string, transform: (line: string) => string): string;
|
|
30
30
|
/** A page's prose lines, in order, with fenced code and its markers dropped. */
|
|
31
31
|
export declare function proseLines(text: string): Generator<string>;
|
|
32
|
+
/**
|
|
33
|
+
* The code inside each `<script>` block a page actually runs, in order.
|
|
34
|
+
*
|
|
35
|
+
* Fenced blocks are skipped, which is the whole reason this reads the page
|
|
36
|
+
* through {@link proseLines} rather than scanning the raw text: a docs page
|
|
37
|
+
* about authoring is mostly ```svelte samples that open with a `<script>`, and
|
|
38
|
+
* those are code being displayed, not code the page runs.
|
|
39
|
+
*/
|
|
40
|
+
export declare function scriptBlocks(text: string): Generator<string>;
|
|
@@ -88,3 +88,25 @@ export function* proseLines(text) {
|
|
|
88
88
|
yield line;
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* A `<script>` element with any attributes, through its closing tag. The open
|
|
93
|
+
* tag has to start a line, indented no further than CommonMark lets HTML be:
|
|
94
|
+
* four spaces make an indented code block, and mid-line means a sentence about
|
|
95
|
+
* a script tag rather than one. Authoring prose writes `` `<script>` `` in
|
|
96
|
+
* inline code constantly, and a page that only talks about a script block has
|
|
97
|
+
* no script block.
|
|
98
|
+
*/
|
|
99
|
+
const SCRIPT_BLOCK = /^ {0,3}<script\b[^>]*>([\s\S]*?)<\/script>/gim;
|
|
100
|
+
/**
|
|
101
|
+
* The code inside each `<script>` block a page actually runs, in order.
|
|
102
|
+
*
|
|
103
|
+
* Fenced blocks are skipped, which is the whole reason this reads the page
|
|
104
|
+
* through {@link proseLines} rather than scanning the raw text: a docs page
|
|
105
|
+
* about authoring is mostly ```svelte samples that open with a `<script>`, and
|
|
106
|
+
* those are code being displayed, not code the page runs.
|
|
107
|
+
*/
|
|
108
|
+
export function* scriptBlocks(text) {
|
|
109
|
+
const prose = [...proseLines(splitFrontmatter(text).body)].join('\n');
|
|
110
|
+
for (const match of prose.matchAll(SCRIPT_BLOCK))
|
|
111
|
+
yield match[1];
|
|
112
|
+
}
|
|
@@ -31,6 +31,10 @@ export interface DocsmithViteOptions {
|
|
|
31
31
|
* keep their unprefixed URLs. Each archived version's pages live under
|
|
32
32
|
* `<content>/<id>/` and are served at `/docs/<id>/…`. Omit for a single,
|
|
33
33
|
* unversioned docs tree (the default).
|
|
34
|
+
*
|
|
35
|
+
* @experimental Outside the 1.0 stability promise. May change in a minor
|
|
36
|
+
* until authors have used versioning for real. An archive freezes content,
|
|
37
|
+
* not dependencies.
|
|
34
38
|
*/
|
|
35
39
|
versions?: DocsVersions;
|
|
36
40
|
}
|
|
@@ -78,7 +78,10 @@ function contentIndexPlugin(options) {
|
|
|
78
78
|
// `dev` leaves the dates as they were until the server restarts.
|
|
79
79
|
let dates;
|
|
80
80
|
const trackedDates = () => (dates ??= commitDates(contentDir, (reason) => {
|
|
81
|
-
|
|
81
|
+
// Truncation and shallow clones both refuse dates deliberately; the
|
|
82
|
+
// reason line says which. "Could not read" would misframe a shallow
|
|
83
|
+
// skip as a hard failure.
|
|
84
|
+
console.warn(`[svelte-docsmith] skipping git-derived page dates under ${contentDir}\n` +
|
|
82
85
|
` ${reason}\n` +
|
|
83
86
|
` Pages will render without a last-updated date, and sitemap entries without \`lastmod\`.`);
|
|
84
87
|
}));
|
package/dist/core/content.d.ts
CHANGED
|
@@ -25,9 +25,11 @@ export type DocsContentItem = {
|
|
|
25
25
|
sourcePath?: string;
|
|
26
26
|
/**
|
|
27
27
|
* The day (`YYYY-MM-DD`) the page's source file last changed, from git, or
|
|
28
|
-
* from the page's own `lastUpdated` frontmatter when it has one.
|
|
29
|
-
*
|
|
30
|
-
*
|
|
28
|
+
* from the page's own `lastUpdated` frontmatter when it has one. Absent when
|
|
29
|
+
* neither source supplies a day — including on a shallow clone, where git
|
|
30
|
+
* dates would be wrong. A calendar day rather than a timestamp: it is
|
|
31
|
+
* rendered as a UTC day, so it reads the same for every reader and matches
|
|
32
|
+
* on the server and the client.
|
|
31
33
|
*/
|
|
32
34
|
lastUpdated?: string;
|
|
33
35
|
/** Estimated reading time in whole minutes (at ~200 wpm), min 1. */
|
package/dist/core/version.d.ts
CHANGED
|
@@ -7,9 +7,18 @@
|
|
|
7
7
|
* anyone edits; superseded releases are frozen copies under their own prefix.
|
|
8
8
|
* See `docs/adr/0001-unprefixed-current-docs.md`. All of it is a no-op when a
|
|
9
9
|
* site declares no versions.
|
|
10
|
+
*
|
|
11
|
+
* **Experimental.** The versioning API sits outside the 1.0 stability promise
|
|
12
|
+
* and may change in a minor until authors have used it for real. An archive
|
|
13
|
+
* freezes content, not dependencies — see
|
|
14
|
+
* `docs/adr/0005-an-archive-freezes-content-not-dependencies.md`.
|
|
10
15
|
*/
|
|
11
16
|
import type { DocsContentItem } from './content.js';
|
|
12
|
-
/**
|
|
17
|
+
/**
|
|
18
|
+
* One documentation version, declared in the `docsmith()` vite plugin.
|
|
19
|
+
*
|
|
20
|
+
* @experimental Outside the 1.0 stability promise. May change in a minor.
|
|
21
|
+
*/
|
|
13
22
|
export type DocsVersion = {
|
|
14
23
|
/** Stable id. Also the URL/directory segment for an archived version. */
|
|
15
24
|
id: string;
|
|
@@ -23,12 +32,22 @@ export type DocsVersion = {
|
|
|
23
32
|
* the docs root, is served unprefixed, and is the folder you edit. `archived`
|
|
24
33
|
* holds frozen copies of superseded releases, each in `<docs root>/<id>/`, in
|
|
25
34
|
* the order they should appear in the switcher (newest first).
|
|
35
|
+
*
|
|
36
|
+
* Freezes content, not dependencies: prose, samples and URLs stay that
|
|
37
|
+
* version's, while imports keep resolving to whatever the app has installed.
|
|
38
|
+
*
|
|
39
|
+
* @experimental Outside the 1.0 stability promise. May change in a minor until
|
|
40
|
+
* authors have used versioning for real.
|
|
26
41
|
*/
|
|
27
42
|
export type DocsVersions = {
|
|
28
43
|
current: DocsVersion;
|
|
29
44
|
archived?: DocsVersion[];
|
|
30
45
|
};
|
|
31
|
-
/**
|
|
46
|
+
/**
|
|
47
|
+
* A {@link DocsVersion} with the URL fields the runtime needs, computed at build time.
|
|
48
|
+
*
|
|
49
|
+
* @experimental Outside the 1.0 stability promise. May change in a minor.
|
|
50
|
+
*/
|
|
32
51
|
export type ResolvedVersion = DocsVersion & {
|
|
33
52
|
/** Absolute URL base: the docs root for `current`, `/docs/<id>` for an archive. */
|
|
34
53
|
basePath: string;
|
|
@@ -98,6 +117,9 @@ export declare function currentVersion(versions: ResolvedVersion[]): ResolvedVer
|
|
|
98
117
|
* Keep only the current version's pages, for `sitemap.xml` and `llms.txt`, so
|
|
99
118
|
* search engines and LLMs index one canonical set. A no-op when the site
|
|
100
119
|
* declares no versions. Works over any record carrying `version`.
|
|
120
|
+
*
|
|
121
|
+
* @experimental Outside the 1.0 stability promise. May change in a minor until
|
|
122
|
+
* authors have used versioning for real.
|
|
101
123
|
*/
|
|
102
124
|
export declare function currentOnly<T extends {
|
|
103
125
|
version?: string;
|
package/dist/core/version.js
CHANGED
|
@@ -153,6 +153,9 @@ export function currentVersion(versions) {
|
|
|
153
153
|
* Keep only the current version's pages, for `sitemap.xml` and `llms.txt`, so
|
|
154
154
|
* search engines and LLMs index one canonical set. A no-op when the site
|
|
155
155
|
* declares no versions. Works over any record carrying `version`.
|
|
156
|
+
*
|
|
157
|
+
* @experimental Outside the 1.0 stability promise. May change in a minor until
|
|
158
|
+
* authors have used versioning for real.
|
|
156
159
|
*/
|
|
157
160
|
export function currentOnly(items, versions) {
|
|
158
161
|
const current = currentVersion(versions);
|
package/dist/index.js
CHANGED
|
@@ -31,10 +31,12 @@ export { default as CTA } from './components/landing/cta.svelte';
|
|
|
31
31
|
export { default as Action } from './components/landing/action.svelte';
|
|
32
32
|
// Config
|
|
33
33
|
export { defineConfig } from './core/index.js';
|
|
34
|
-
// Versioned docs
|
|
35
|
-
//
|
|
36
|
-
//
|
|
37
|
-
//
|
|
34
|
+
// Versioned docs (experimental — outside the 1.0 stability promise). Declare
|
|
35
|
+
// `versions` in the `docsmith()` vite plugin; the resolved manifest is exported
|
|
36
|
+
// from `svelte-docsmith/content` and passed to `DocsShell`. `currentOnly`
|
|
37
|
+
// scopes sitemap.xml / llms.txt to the current version, so archived releases
|
|
38
|
+
// don't compete with it in search results. An archive freezes content, not
|
|
39
|
+
// dependencies.
|
|
38
40
|
export { currentOnly } from './core/index.js';
|
|
39
41
|
// Search engine (framework-agnostic; for building a custom search UI over the
|
|
40
42
|
// generated `svelte-docsmith/search` index)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svelte-docsmith",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "A framework for building beautiful documentation sites with Svelte.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "George Daskalakis",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
},
|
|
67
67
|
"repository": {
|
|
68
68
|
"type": "git",
|
|
69
|
-
"url": "https://github.com/geodask/svelte-docsmith.git"
|
|
69
|
+
"url": "git+https://github.com/geodask/svelte-docsmith.git"
|
|
70
70
|
},
|
|
71
71
|
"license": "MIT",
|
|
72
72
|
"peerDependencies": {
|