@mnemosyne_os/affine-reader 0.1.2 → 0.1.3

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.
@@ -70,12 +70,33 @@ function exportWorkspace(db, outDir, options = {}) {
70
70
  const blobNames = new Map();
71
71
  for (const blob of (0, read_1.readBlobIndex)(db, schema))
72
72
  blobNames.set(blob.key, blobFileName(blob.key, blob.mime));
73
+ // A link from one document to another becomes a relative link to the file that
74
+ // document was written to, so the export is browsable on its own and in any
75
+ // editor that reads a folder of Markdown. Rendering it as an `affine-doc:` id
76
+ // would make every internal link dead the moment it leaves the app.
77
+ //
78
+ // The index has to be read BEFORE the documents are rendered, because a link
79
+ // can point at a document that has not been written yet.
80
+ const workspaceId = (0, read_1.readWorkspaceId)(db, schema) ?? '';
81
+ const docNames = new Map();
82
+ const docTitles = new Map();
83
+ for (const entry of (0, read_1.readDocIndex)((0, read_1.loadDoc)(db, schema, schema === 'v2' ? workspaceId : null).doc)) {
84
+ docNames.set(entry.id, fileNameFor(entry.title, entry.id));
85
+ if (entry.title)
86
+ docTitles.set(entry.id, entry.title);
87
+ }
73
88
  const rendered = (0, read_1.readWorkspace)(db, {
74
89
  ...options,
75
90
  blobUrl: (key) => {
76
91
  const name = blobNames.get(key);
77
92
  return name ? `blobs/${name}` : (options.blobUrl?.(key) ?? null);
78
93
  },
94
+ // A doc in the trash, or one the index does not carry, has no file to point
95
+ // at. It keeps the caller's answer rather than a link that goes nowhere.
96
+ docUrl: (docId) => docNames.get(docId) ?? options.docUrl?.(docId) ?? `affine-doc:${docId}`,
97
+ // The label the reader sees. An inline reference carries no title, so
98
+ // without this the link comes out as `[](target.md)` and shows as nothing.
99
+ docTitle: (docId) => docTitles.get(docId) ?? options.docTitle?.(docId) ?? docId,
79
100
  });
80
101
  let blobsWritten = 0;
81
102
  if (options.writeBlobs !== false && rendered.blobs.length > 0) {
package/dist/read.js CHANGED
@@ -173,6 +173,7 @@ function readWorkspace(db, options = {}) {
173
173
  doc: loaded.doc,
174
174
  buildBlobUrl: (key) => options.blobUrl?.(key) ?? `affine-blob:${key}`,
175
175
  buildDocUrl: (docId) => options.docUrl?.(docId) ?? `affine-doc:${docId}`,
176
+ renderDocTitle: options.docTitle,
176
177
  };
177
178
  const parsed = (0, parser_1.parsePageDoc)(ctx);
178
179
  docs.push({
package/dist/types.d.ts CHANGED
@@ -75,4 +75,12 @@ export interface ReadOptions {
75
75
  blobUrl?: (key: string) => string | null;
76
76
  /** How a link to another AFFiNE doc is rendered. */
77
77
  docUrl?: (docId: string) => string;
78
+ /**
79
+ * The visible label for a link to another doc.
80
+ *
81
+ * An inline reference carries no title of its own, so without this the parser
82
+ * writes `[](target.md)`: a link with an empty label, which most Markdown
83
+ * readers render as nothing at all.
84
+ */
85
+ docTitle?: (docId: string) => string;
78
86
  }
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@mnemosyne_os/affine-reader",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Read a local AFFiNE workspace (SQLite + Yjs) and render its documents to Markdown. No BlockSuite at runtime, no native module, read-only.",
5
5
  "license": "MIT",
6
6
  "author": "Tony Trochet <tony@xpacegems.com> (https://xpacegems.com)",
7
7
  "homepage": "https://mnemosyne-os.io",
8
8
  "repository": {
9
9
  "type": "git",
10
- "url": "git+https://github.com/Mnemosyne-OS/Mnemosyne-Neural-OS.git"
10
+ "url": "git+https://github.com/Mnemosyne-OS/Mnemosyne-Neural-OS.git",
11
+ "directory": "packages/affine-reader"
11
12
  },
12
13
  "bugs": {
13
14
  "url": "https://github.com/Mnemosyne-OS/Mnemosyne-Neural-OS/issues"