mirror of
https://github.com/Dasemu/Synapse.git
synced 2026-11-26 07:16:17 +00:00
Track imported pages/blocks, stable fallback ids, per-document savepoints, rename-safe page lookup, append on first import into existing pages. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
54 lines
3.6 KiB
Markdown
54 lines
3.6 KiB
Markdown
# Logseq import
|
|
|
|
Crate `synapse-import`: `import_logseq(src, &graph, &ImportOptions, progress) -> Report`.
|
|
CLI: `cargo run --release -p synapse-import --example import -- <logseq_dir> <graph_dir> [--skip-existing]`.
|
|
|
|
## Pipeline
|
|
1. **Scan** `pages/`, `journals/` (`.md`, `.org`) and `assets/` (recursive). Settings are read from
|
|
`logseq/config.edn`: `:journal/file-name-format`, `:journal/page-title-format`,
|
|
`:file/name-format` (`:triple-lowbar` → `___` is the namespace separator, otherwise `.`).
|
|
2. **Assets**: every file in `assets/` is streamed into the blob store (`put_asset_file`, constant
|
|
memory) keeping its original file name.
|
|
3. **Parse** (rayon): outline → block tree. Fractional positions via `position::between`.
|
|
4. **Pages**, then **aliases**, then **blocks**, written on one thread.
|
|
|
|
## Mapping
|
|
- File name → title: `a___b.md` → `a/b`, `%2F`/url-encoding decoded. A `title::` page property
|
|
overrides it. Journals `2024_03_15.md` → journal page `2024-03-15`.
|
|
- `[[Mar 15th, 2024]]` (configured title format) is rewritten to `[[2024-03-15]]`.
|
|
- Page properties = lines before the first bullet, YAML front matter, or a first block that holds
|
|
only properties. `alias::` also registers aliases. Block `key:: value` lines go to block
|
|
properties (not the content); `id::` becomes the block id (so `((uuid))` refs keep working);
|
|
`collapsed:: true` sets the flag.
|
|
- Assets: `../assets/x%20y.png` → `asset://<blake3>` in place (``; `?`/`#`
|
|
suffixes kept). Missing files are left as is and reported.
|
|
- `.org` files: one raw root block per top-level heading, no parsing; listed in `Report::org_files`.
|
|
- Timestamps: page `created_at` = file birth time (≤ mtime), `updated_at` = mtime; blocks inherit
|
|
them. `origin_journal` = earliest journal referencing the page (aliases resolved), else the
|
|
file's creation day. Journal pages keep core's midnight timestamps.
|
|
|
|
## Re-import and native content
|
|
The importer records what it wrote in two local tables (`import_pages`: source file → page id,
|
|
`import_blocks`: block id → state hash). Re-imports use them so Synapse content is never lost:
|
|
- Pages are found by source file first, so a page renamed in Synapse is updated, not duplicated.
|
|
- Block ids: Logseq `id::` when present, otherwise UUIDv5 of (source file, parent id, content,
|
|
duplicate index). Inserting or moving a block elsewhere in a file does not change other ids.
|
|
- Only blocks the importer wrote are ever overwritten or deleted, and only while unedited in
|
|
Synapse. Edited blocks keep the Synapse version (warning if the file changed too); a removed
|
|
block that was edited or has native children is kept (warning). Native blocks are never touched.
|
|
- First import into an existing page (e.g. today's journal) appends the imported blocks after the
|
|
native ones; page properties are merged without overriding existing keys.
|
|
- A block deleted in Synapse stays deleted unless the file changed it.
|
|
- Each document is written in its own savepoint; a failure rolls the document back and becomes a
|
|
warning. The whole write phase is one transaction.
|
|
- `ExistingPages::Skip` leaves any page that already has blocks alone.
|
|
|
|
## Report / progress
|
|
`Progress { phase, done, total }` (phases: Scanning, Assets, Parsing, Pages, Blocks) and
|
|
`Report { pages, journals, blocks, assets, bytes, updated, unchanged, org_files, warnings }`.
|
|
|
|
## Known limits
|
|
- Not parsed: org-mode syntax, whiteboards, `draws/`, namespace parent stubs, Logseq queries.
|
|
- Speed is bound by core's per-block savepoint inside the import transaction: 208k blocks
|
|
(10k pages) ≈ 60 s; re-importing an unchanged graph ≈ 1.3 s.
|