@dogsbay/format-gitbook 0.2.0-beta.133 → 0.2.0-beta.135

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/corpus.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  /** The corpus an importer reads: `@dogsbay/corpus`, shared by every format's browser import. */
2
- export { corpusFromMap, type Corpus, type CorpusFiles, type Unfetched, unfetchedMessage } from "@dogsbay/corpus";
2
+ export { corpusFromMap, type Corpus, type CorpusFiles, type Unfetched, unfetchedMessage, pendingCopies, withPages } from "@dogsbay/corpus";
package/dist/corpus.js CHANGED
@@ -1,2 +1,2 @@
1
1
  /** The corpus an importer reads: `@dogsbay/corpus`, shared by every format's browser import. */
2
- export { corpusFromMap, unfetchedMessage } from "@dogsbay/corpus";
2
+ export { corpusFromMap, unfetchedMessage, pendingCopies, withPages } from "@dogsbay/corpus";
package/dist/import.d.ts CHANGED
@@ -23,5 +23,7 @@ export interface GitbookImportResult {
23
23
  /** Docs roots to mirror non-`.md` assets from (corpus-relative folder + slug prefix). */
24
24
  assetRoots: GitbookAssetRoot[];
25
25
  ledger: ImportLedgerEntry[];
26
+ /** The corpus file each page was converted from: `sources[i]` is `pages[i]`'s. */
27
+ sources: string[];
26
28
  }
27
29
  export declare function importGitbookCorpus(corpus: Corpus, opts?: GitbookImportOptions): GitbookImportResult;
package/dist/import.js CHANGED
@@ -6,6 +6,7 @@ export function importGitbookCorpus(corpus, opts = {}) {
6
6
  const { pages: sources, nav, redirects, spaces, assetRoots } = loadGitbookCorpus(corpus, opts);
7
7
  const pages = [];
8
8
  const ledger = [];
9
+ const pageFiles = [];
9
10
  // A page written under another file name (README.md → index.md, a landing page → index.md):
10
11
  // links to it follow the rename.
11
12
  const renames = new Map();
@@ -37,6 +38,7 @@ export function importGitbookCorpus(corpus, opts = {}) {
37
38
  // to the H1 / slug (review #6).
38
39
  const fmTitle = typeof frontmatter.title === "string" && frontmatter.title.trim() ? frontmatter.title : undefined;
39
40
  const title = fmTitle || h1?.text || prettify(ps.slug.slice(ps.slug.lastIndexOf("/") + 1));
41
+ pageFiles.push(ps.path);
40
42
  pages.push({
41
43
  slug: ps.slug,
42
44
  title,
@@ -58,5 +60,5 @@ export function importGitbookCorpus(corpus, opts = {}) {
58
60
  });
59
61
  }
60
62
  }
61
- return { pages, nav, redirects, spaces, assetRoots, ledger };
63
+ return { pages, nav, redirects, spaces, assetRoots, ledger, sources: pageFiles };
62
64
  }
package/dist/migrate.js CHANGED
@@ -1,4 +1,4 @@
1
- import { corpusFromMap, unfetchedMessage } from "./corpus.js";
1
+ import { corpusFromMap, pendingCopies, unfetchedMessage } from "./corpus.js";
2
2
  import { importGitbookCorpus } from "./import.js";
3
3
  import { gitbookProject } from "./project.js";
4
4
  /** The ledger line for a conversion that still needs files, or nothing. */
@@ -21,7 +21,7 @@ export async function migrate(input) {
21
21
  // A file it needed was not given: that, not the error, is the answer
22
22
  const read = corpus.missing();
23
23
  if (read.length)
24
- return { files: new Map(), ledger: unfetchedLedger(read, e), redirects: [], unfetched: { read, copy: [] } };
24
+ return { files: new Map(), ledger: unfetchedLedger(read, e), redirects: [], unfetched: { read, copy: [], copyTo: [] } };
25
25
  throw e;
26
26
  }
27
27
  const files = new Map(project.files);
@@ -31,8 +31,8 @@ export async function migrate(input) {
31
31
  if (bytes !== undefined)
32
32
  files.set(to, bytes);
33
33
  else
34
- copy.push(from);
34
+ copy.push({ from, to });
35
35
  }
36
36
  const read = corpus.missing();
37
- return { files, ledger: [...unfetchedLedger(read), ...project.ledger], redirects: project.redirects, unfetched: { read, copy: copy.sort() } };
37
+ return { files, ledger: [...unfetchedLedger(read), ...project.ledger], redirects: project.redirects, unfetched: { read, ...pendingCopies(copy) } };
38
38
  }
package/dist/project.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { ImportLedgerEntry } from "@dogsbay/types";
2
- import type { Corpus } from "./corpus.js";
2
+ import { type Corpus } from "./corpus.js";
3
3
  import type { GitbookImportResult } from "./import.js";
4
4
  export interface GitbookProjectOptions {
5
5
  siteName: string;
package/dist/project.js CHANGED
@@ -7,6 +7,7 @@
7
7
  */
8
8
  import * as yaml from "js-yaml";
9
9
  import { gitbookVisible, within } from "@dogsbay/detect";
10
+ import { withPages } from "./corpus.js";
10
11
  function yamlQuote(s) {
11
12
  return /[:#&*!|>%@`,'"[\]{}]|^\s|\s$/.test(s) ? JSON.stringify(s) : s;
12
13
  }
@@ -95,7 +96,9 @@ export function gitbookProject(result, corpus, opts) {
95
96
  const taken = new Set();
96
97
  let fragments = 0;
97
98
  let collisions = 0;
98
- for (const page of result.pages) {
99
+ // Each written page's source file → the page, for the notes about that file
100
+ const pageOf = new Map();
101
+ for (const [i, page] of result.pages.entries()) {
99
102
  const dst = `content/${page.slug}.md`;
100
103
  if (taken.has(dst.toLowerCase())) {
101
104
  collisions += 1;
@@ -103,6 +106,8 @@ export function gitbookProject(result, corpus, opts) {
103
106
  continue;
104
107
  }
105
108
  taken.add(dst.toLowerCase());
109
+ if (result.sources?.[i] !== undefined)
110
+ pageOf.set(result.sources[i], dst);
106
111
  const body = page.bodyMarkdown ?? "";
107
112
  const text = body.endsWith("\n") ? body : body + "\n";
108
113
  if (page.fragment) {
@@ -170,6 +175,8 @@ export function gitbookProject(result, corpus, opts) {
170
175
  redirects.push(r);
171
176
  }
172
177
  const pages = result.pages.filter((p) => !p.fragment).length;
173
- files.set("MIGRATION.md", migrationNotes({ ...opts, pages, fragments, spaces: result.spaces, redirects: redirects.length, ledger }));
174
- return { files, assets: copies, redirects, ledger, stats: { pages, fragments, collisions, spaces: result.spaces } };
178
+ // Each note about a written page's file names that page
179
+ const placed = withPages(ledger, pageOf);
180
+ files.set("MIGRATION.md", migrationNotes({ ...opts, pages, fragments, spaces: result.spaces, redirects: redirects.length, ledger: placed }));
181
+ return { files, assets: copies, redirects, ledger: placed, stats: { pages, fragments, collisions, spaces: result.spaces } };
175
182
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dogsbay/format-gitbook",
3
- "version": "0.2.0-beta.133",
3
+ "version": "0.2.0-beta.135",
4
4
  "description": "GitBook format plugin for Dogsbay — imports GitBook Git Sync (and legacy gitbook-cli) corpora by translating the Git Sync markdown dialect to Dogsbay-MD. ./migrate converts a corpus given as a map of files in the browser (no Node), the same import the CLI runs.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -25,10 +25,10 @@
25
25
  ],
26
26
  "dependencies": {
27
27
  "js-yaml": "^5.2.1",
28
- "@dogsbay/corpus": "0.2.0-beta.133",
29
- "@dogsbay/format-dogsbay-md": "0.2.0-beta.133",
30
- "@dogsbay/detect": "0.2.0-beta.133",
31
- "@dogsbay/types": "0.2.0-beta.133"
28
+ "@dogsbay/corpus": "0.2.0-beta.135",
29
+ "@dogsbay/detect": "0.2.0-beta.135",
30
+ "@dogsbay/format-dogsbay-md": "0.2.0-beta.135",
31
+ "@dogsbay/types": "0.2.0-beta.135"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@types/js-yaml": "^4.0.9",