@dogsbay/format-vitepress 0.2.0-beta.132 → 0.2.0-beta.134
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/dist/import.d.ts +2 -0
- package/dist/import.js +3 -0
- package/dist/migrate.d.ts +17 -2
- package/dist/migrate.js +38 -8
- package/package.json +6 -6
package/dist/import.d.ts
CHANGED
|
@@ -24,5 +24,7 @@ export interface VitepressCorpusImport {
|
|
|
24
24
|
components: Record<string, number>;
|
|
25
25
|
/** Per-page constructs mapped with caveats, pages that failed, and the loader's warnings. */
|
|
26
26
|
ledger: ImportLedgerEntry[];
|
|
27
|
+
/** The corpus file each page was converted from: `sources[i]` is `pages[i]`'s. */
|
|
28
|
+
sources: string[];
|
|
27
29
|
}
|
|
28
30
|
export declare function importVitepressCorpus(corpus: Corpus, opts?: VitepressLoadOptions): VitepressCorpusImport;
|
package/dist/import.js
CHANGED
|
@@ -8,6 +8,7 @@ export function importVitepressCorpus(corpus, opts = {}) {
|
|
|
8
8
|
const pages = [];
|
|
9
9
|
const components = {};
|
|
10
10
|
const ledger = [];
|
|
11
|
+
const sources = [];
|
|
11
12
|
for (const ps of loaded.pages) {
|
|
12
13
|
try {
|
|
13
14
|
const content = corpus.text(ps.path);
|
|
@@ -30,6 +31,7 @@ export function importVitepressCorpus(corpus, opts = {}) {
|
|
|
30
31
|
const heroName = typeof frontmatter.hero?.name === "string"
|
|
31
32
|
? (frontmatter.hero.name)
|
|
32
33
|
: undefined;
|
|
34
|
+
sources.push(ps.path);
|
|
33
35
|
pages.push({
|
|
34
36
|
slug: ps.slug,
|
|
35
37
|
title: fmTitle || h1?.text || heroName || titleFromSlug(ps.slug),
|
|
@@ -72,5 +74,6 @@ export function importVitepressCorpus(corpus, opts = {}) {
|
|
|
72
74
|
warnings: loaded.warnings,
|
|
73
75
|
components,
|
|
74
76
|
ledger,
|
|
77
|
+
sources,
|
|
75
78
|
};
|
|
76
79
|
}
|
package/dist/migrate.d.ts
CHANGED
|
@@ -6,11 +6,17 @@
|
|
|
6
6
|
* clock or network. Find the project with `@dogsbay/detect` first.
|
|
7
7
|
*/
|
|
8
8
|
import type { ImportLedgerEntry } from "@dogsbay/types";
|
|
9
|
-
import { type CorpusFiles } from "@dogsbay/corpus";
|
|
10
|
-
export type { CorpusFiles } from "@dogsbay/corpus";
|
|
9
|
+
import { type CorpusFiles, type Unfetched } from "@dogsbay/corpus";
|
|
10
|
+
export type { CorpusFiles, Unfetched } from "@dogsbay/corpus";
|
|
11
11
|
export interface MigrateInput {
|
|
12
12
|
/** The project: paths relative to its root (a detection's `root`), text or bytes. */
|
|
13
13
|
files: CorpusFiles;
|
|
14
|
+
/**
|
|
15
|
+
* Every path of the project (relative to the same root as `files`), when the host lists more
|
|
16
|
+
* than it fetched (a GitHub tree). The import then sees the repo as it is, and `unfetched`
|
|
17
|
+
* says what it needed from those not given: fetch them and call `migrate` again.
|
|
18
|
+
*/
|
|
19
|
+
paths?: Iterable<string>;
|
|
14
20
|
/** Defaults to the config's `title`, else "Docs". */
|
|
15
21
|
siteName?: string;
|
|
16
22
|
siteUrl?: string;
|
|
@@ -21,5 +27,14 @@ export interface MigrateResult {
|
|
|
21
27
|
/** The Dogsbay project: dogsbay.config.yml, content/** (pages, nav.json, _assets), MIGRATION.md. */
|
|
22
28
|
files: Map<string, string | Uint8Array>;
|
|
23
29
|
ledger: ImportLedgerEntry[];
|
|
30
|
+
/**
|
|
31
|
+
* The listed `paths` the conversion needed but `files` did not hold. `read`: it read them,
|
|
32
|
+
* so fetch them and convert again (each round can find one more level of an include or
|
|
33
|
+
* `require` chain: cap the rounds). While `read` is not empty the result is not a
|
|
34
|
+
* conversion; when the import could not go on, `files` is empty and the ledger says where
|
|
35
|
+
* it stopped. `copy`: assets the output copies; fetch them for the finished files, no
|
|
36
|
+
* rerun. Both empty: the result is complete.
|
|
37
|
+
*/
|
|
38
|
+
unfetched: Unfetched;
|
|
24
39
|
}
|
|
25
40
|
export declare function migrate(input: MigrateInput): Promise<MigrateResult>;
|
package/dist/migrate.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import { corpusFromMap } from "@dogsbay/corpus";
|
|
2
|
-
import { dogsbayMdPageFiles, mountCopies } from "@dogsbay/format-dogsbay-md/browser";
|
|
1
|
+
import { corpusFromMap, pageSources, pendingCopies, unfetchedMessage, withPages } from "@dogsbay/corpus";
|
|
2
|
+
import { dogsbayMdPageFiles, dogsbayMdPagePath, mountCopies } from "@dogsbay/format-dogsbay-md/browser";
|
|
3
3
|
import { importVitepressCorpus } from "./import.js";
|
|
4
|
+
/** The ledger line for a conversion that still needs files, or nothing. */
|
|
5
|
+
function unfetchedLedger(read, stoppedOn) {
|
|
6
|
+
const message = unfetchedMessage(read, stoppedOn);
|
|
7
|
+
return message ? [{ severity: "warning", code: "unfetched", message }] : [];
|
|
8
|
+
}
|
|
4
9
|
const yamlQuote = (s) => JSON.stringify(s);
|
|
5
10
|
function buildConfig(siteName, siteUrl) {
|
|
6
11
|
const lines = [`schemaVersion: 1`, `site:`, ` name: ${yamlQuote(siteName)}`, ` basePath: ""`];
|
|
@@ -39,26 +44,51 @@ function migrationNotes(a) {
|
|
|
39
44
|
return lines.join("\n") + "\n";
|
|
40
45
|
}
|
|
41
46
|
export async function migrate(input) {
|
|
42
|
-
const corpus = corpusFromMap(input.files);
|
|
43
|
-
|
|
47
|
+
const corpus = corpusFromMap(input.files, { paths: input.paths });
|
|
48
|
+
let imported;
|
|
49
|
+
try {
|
|
50
|
+
imported = importVitepressCorpus(corpus);
|
|
51
|
+
}
|
|
52
|
+
catch (e) {
|
|
53
|
+
// A file it needed was not given: that, not the error, is the answer
|
|
54
|
+
const read = corpus.missing();
|
|
55
|
+
if (read.length)
|
|
56
|
+
return { files: new Map(), ledger: unfetchedLedger(read, e), unfetched: { read, copy: [], copyTo: [] } };
|
|
57
|
+
throw e;
|
|
58
|
+
}
|
|
44
59
|
const siteName = input.siteName?.trim() || imported.siteName?.trim() || "Docs";
|
|
45
60
|
const files = new Map();
|
|
46
61
|
// Assets first, then the pages: `convert` copies the mounts before it writes the pages, so a
|
|
47
62
|
// page wins over a file at the same path
|
|
48
|
-
|
|
63
|
+
const pageFiles = dogsbayMdPageFiles(imported.pages, imported.nav);
|
|
64
|
+
// One file per output path, the last mount's (public/ and .vitepress/public/ both land in
|
|
65
|
+
// _assets/), whether its bytes were given or not; a page at the same path wins
|
|
66
|
+
const winners = new Map();
|
|
67
|
+
for (const { from, to } of mountCopies(corpus.paths, imported.assetDirs))
|
|
68
|
+
winners.set(to, from);
|
|
69
|
+
const copy = [];
|
|
70
|
+
for (const [to, from] of winners) {
|
|
71
|
+
if (pageFiles.has(to))
|
|
72
|
+
continue;
|
|
49
73
|
const bytes = input.files.get(from);
|
|
50
74
|
if (bytes !== undefined)
|
|
51
75
|
files.set(`content/${to}`, bytes);
|
|
76
|
+
else
|
|
77
|
+
copy.push({ from, to: `content/${to}` });
|
|
52
78
|
}
|
|
53
|
-
for (const [path, text] of
|
|
79
|
+
for (const [path, text] of pageFiles)
|
|
54
80
|
files.set(`content/${path}`, text);
|
|
81
|
+
// Each note about a page's file names the page written from it
|
|
82
|
+
const pageOf = pageSources(imported.pages.map((p, i) => ({ file: imported.sources[i], path: `content/${dogsbayMdPagePath(p)}` })));
|
|
83
|
+
const ledger = withPages(imported.ledger, pageOf);
|
|
55
84
|
files.set("dogsbay.config.yml", buildConfig(siteName, input.siteUrl));
|
|
56
85
|
files.set("MIGRATION.md", migrationNotes({
|
|
57
86
|
siteName,
|
|
58
87
|
sourceLabel: input.sourceLabel ?? "VitePress project",
|
|
59
88
|
pages: imported.pages.length,
|
|
60
89
|
navSource: imported.navSource,
|
|
61
|
-
ledger
|
|
90
|
+
ledger,
|
|
62
91
|
}));
|
|
63
|
-
|
|
92
|
+
const read = corpus.missing();
|
|
93
|
+
return { files, ledger: [...unfetchedLedger(read), ...ledger], unfetched: { read, ...pendingCopies(copy) } };
|
|
64
94
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dogsbay/format-vitepress",
|
|
3
|
-
"version": "0.2.0-beta.
|
|
3
|
+
"version": "0.2.0-beta.134",
|
|
4
4
|
"description": "VitePress format plugin for Dogsbay — imports VitePress docs projects into TreeNode[] by translating VitePress containers, code-fence conventions, snippets and includes to Dogsbay-MD.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -24,11 +24,11 @@
|
|
|
24
24
|
"README.md"
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@dogsbay/
|
|
28
|
-
"@dogsbay/
|
|
29
|
-
"@dogsbay/
|
|
30
|
-
"@dogsbay/literal": "0.2.0-beta.
|
|
31
|
-
"@dogsbay/types": "0.2.0-beta.
|
|
27
|
+
"@dogsbay/corpus": "0.2.0-beta.134",
|
|
28
|
+
"@dogsbay/detect": "0.2.0-beta.134",
|
|
29
|
+
"@dogsbay/format-dogsbay-md": "0.2.0-beta.134",
|
|
30
|
+
"@dogsbay/literal": "0.2.0-beta.134",
|
|
31
|
+
"@dogsbay/types": "0.2.0-beta.134"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@types/node": "^25.9.5",
|