Mapa: the importer's icons, covers and column widths (columns and icons spec, phase 4)
A Notion page's icon and cover become its icon and banner, prepared before its write under notion_images' own look prints: emoji checked against the list; uploaded and custom icons capped at 128 KB and 512 pixels; covers from Notion's file store and its gallery only (the notion module's leaf pair, b8398e7). ImportCreate writes the look; ImportUpdate writes renamed, styled, edited in one transaction; unchanged compares the look; a passing failure keeps the look a page has. The report counts icons and banners by reason, and uneven column widths. Gates I20 to I25; seven mutations. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Squashed from feat/import-looks into main.
41 files changed,
+1,347
−47
AGENTS.md+7 −1copy-review/import-looks/result.json+53 −0copy-review/import-looks/strings.json+74 −0docs/superpowers/specs/2026-11-17-notion-import.md+9 −4docs/superpowers/specs/2026-11-22-mapa-columns-icons.md+11 −0go.mod+1 −1go.sum+6 −0internal/mapa/import_convert.go+12 −4internal/mapa/import_history.go+4 −2internal/mapa/import_images.go+7 −0internal/mapa/import_images_place.go+38 −1internal/mapa/import_images_store.go+4 −0internal/mapa/import_looks.go+276 −0internal/mapa/import_looks_test.go+370 −0internal/mapa/import_report.go+30 −7internal/mapa/import_safety_test.go+6 −2internal/mapa/import_set.go+3 −0internal/mapa/import_store.go+35 −2internal/mapa/import_write.go+35 −3internal/mapa/markup/testdata/corpus/import.json+3 −0internal/mapa/markup/testdata/editor.json+4 −1internal/mapa/markup/testdata/golden.json+3 −0internal/mapa/notionmd/blocks.go+28 −0internal/mapa/notionmd/fixtures_blocks_test.go+23 −1internal/mapa/notionmd/mapper.go+0 −6internal/mapa/notionmd/render.go+1 −2internal/mapa/notionmd/testdata/fixtures/columns-equal-ones.json+54 −0internal/mapa/notionmd/testdata/fixtures/columns-even.json+53 −0internal/mapa/notionmd/testdata/fixtures/columns-widths.json+54 −0internal/mapa/notionmd/testdata/fixtures/page-icon-cover.json+8 −2internal/mapa/notionmd/testdata/golden/columns-equal-ones.json+5 −0internal/mapa/notionmd/testdata/golden/columns-equal-ones.md+13 −0internal/mapa/notionmd/testdata/golden/columns-even.json+5 −0internal/mapa/notionmd/testdata/golden/columns-even.md+13 −0internal/mapa/notionmd/testdata/golden/columns-widths.json+8 −0internal/mapa/notionmd/testdata/golden/columns-widths.md+13 −0internal/mapa/notionmd/testdata/golden/page-icon-cover.json+1 −5internal/mapa/notionmd/tree.go+17 −3internal/mapa/templates/import.html+4 −0scripts/mutate/import_looks.go+55 −0scripts/mutate/main.go+1 −0
CI passed — run details
CI log
=== editor ===
cd editor && npm ci --no-audit --no-fund --loglevel=error
added 16 packages in 309ms
cd editor && node build-bundles.mjs
wrote internal/mapa/static/editor.bad1b29c273b6a86.js (364471 bytes, 114.4KB gzipped; L12 budget 120KB)
cd editor && node --test
✔ a badge is named for what it does, starting with its visible word (1.006146ms)
✔ first words stop at five words or forty characters (0.170646ms)
✔ the field keeps one trimmed line, without brackets (0.350269ms)
✔ the field holds at most MaxAlt bytes, cut at a character (0.899538ms)
✔ a block becomes column 1 of two, and undo gives it back (12.34731ms)
✔ a selection over blocks moves them all into column 1 (2.81616ms)
✔ no layout is made inside a layout (0.765629ms)
✔ Add a column, Remove this column and Undo columns (5.552614ms)
✔ Undo columns puts the blocks in reading order (1.166512ms)
✔ Backspace in an empty column takes the column away (1.134252ms)
✔ ⌥⌘→ and ⌥⌘← move between columns (0.703925ms)
✔ typing a fence line in a column never closes it (D16) (7.287849ms)
✔ a selection holding a layout makes no nested layout (H1) (2.487943ms)
✔ a fence typed after a break in a column stays in the column (H2) (3.653032ms)
✔ code holding a fence line and ::: stays code in its column (H2) (1.364008ms)
✔ Backspace after a layout and Delete before one join nothing (M4) (0.778403ms)
✔ deleting across columns keeps every column (M3) (1.967457ms)
✔ a layout pasted into a column arrives as its blocks (M1) (2.821931ms)
✔ copying inside one column puts no fence on the clipboard (M2) (0.58837ms)
✔ typing goes on in the column after a structural reparse (round 2) (6.39172ms)
✔ a structural reparse in a column leaves code as it was (round 2) (2.104171ms)
✔ days and weeks move across months and years (1.55916ms)
✔ a month keeps the day, or takes the month's last (0.376057ms)
✔ the grid is six weeks from Monday, as the month calendar draws it (2.136872ms)
✔ the grid starts the week where the locale does (0.646328ms)
✔ the keys move a day, a week, a month and a year (0.471644ms)
✔ the picked day is the chip [[ makes for a date (19.984597ms)
✔ Insert → Today's date still puts today in at once (2.207632ms)
✔ / offers Date, the picker, and Today's date beside it (0.40467ms)
✔ after a ! the chip goes in after a space, never as an embed (4.284583ms)
✔ where the Markdown would read the chip differently, it is refused (4.193805ms)
✔ over a selection the chip goes after it and the words stay (3.106448ms)
✔ today is the day in the viewer's zone (18.971458ms)
✔ every offered locale has cases (1.077357ms)
✔ dates.mjs writes every date Go writes, byte for byte (5.149766ms)
✔ a chip, the month and the week, in three locales (0.635017ms)
✔ dates.json is what ICU gives, byte for byte (469.277101ms)
✔ L1: mounting then serialising gives cleanBody(body), byte for byte (102.404974ms)
ℹ 904 bodies
✔ L1: mounting a stored body adds nothing, and saving it writes nothing new (87.719651ms)
✔ L2: one edited block changes only that block's bytes; undo gives the body back (141.549992ms)
ℹ 891 single-block edits
✔ L2: inserting or deleting a block changes bytes only at the new seams, by Join (159.407835ms)
ℹ 899 inserts, 837 deletes
✔ L3: seeded edits keep the document and its Markdown saying the same thing (5188.750942ms)
ℹ 21696 edits over 904 bodies
✔ L3: Link to a page makes exactly one chip, and changes nothing else (1251.011518ms)
ℹ 4724 links over 904 bodies; refused: {"A page link can’t hold another link or a line break. Select plain words.":945,"A page link can’t show [ or ]]. Select words without them.":404,"Select some words to link them to a page.":174,"Linked here, the Markdown around these words would read differently: a ! before them makes an embed, and a stray ` or * pairs up. Select other words.":18}
✔ L3: a picked date is one more date chip, or refused where a letter would be too (1373.940213ms)
ℹ over 904 bodies: {"inserted":5356,"spaced":23,"refused":45,"unstable":9}
✔ linear: trailing spaces (25.354371ms)
✔ linear: trailing whitespace (34.055781ms)
✔ linear: unclosed web links (37.062995ms)
✔ linear: web links with no address (20.433831ms)
✔ linear: unclosed wiki links (17.207269ms)
✔ linear: unclosed embeds (22.403119ms)
✔ linear: closes only (9.479493ms)
✔ the selected words become the chip's shown text (13.343076ms)
✔ words that are the title make a plain [[Title]] (4.500572ms)
✔ spaces at the selection's edges stay outside the chip (1.254686ms)
✔ a date makes a date link, in a heading, an item and a quote (7.636246ms)
✔ bold words lose their bold: a chip carries no marks in Mapa's Markdown (1.51049ms)
✔ only the linked block's bytes change, and undo gives the body back (3.192828ms)
✔ a selection across blocks, over a chip or a break, or of brackets is refused (1.757879ms)
✔ a target the words cannot be linked to as typed is refused (0.300076ms)
✔ ⌘L: over a selection it opens Page link; with none it types [[; in code it does nothing (2.705837ms)
✔ web-linked words are refused: the address would be lost (review M4) (1.568938ms)
✔ words whose Markdown would read otherwise are refused (review M3) (2.127283ms)
✔ ⌘A then ⌘L says why, instead of doing nothing (review low 1) (0.396805ms)
✔ linkCheck says why it refuses (review low 2) (1.528554ms)
✔ golden file has bodies (0.921158ms)
✔ markup.mjs parses every body into Go's blocks, byte offsets and all (38.111028ms)
✔ markup.mjs strips and spans every block as Go does (42.321986ms)
✔ the schema's toDOM draws every body as Go renders it (68.17956ms)
✔ emphasis draws the four pinned outputs (21.589382ms)
✔ a body ends in the editor's empty paragraph (0.221961ms)
✔ the editor labels date chips as Go does, in every locale L4 holds (9.017857ms)
✔ a POST that never answers is aborted after the timeout (23.430806ms)
✔ a keepalive POST carries no signal, and an answer clears the timer (1.250077ms)
✔ autosave sends only what differs, and the tab owns the draft it wrote (13.053067ms)
✔ an offered draft never commits by itself; Save commits it (1.658965ms)
✔ reload, then close: sessionStorage says the draft is this tab's own (0.73359ms)
✔ closing carries text not yet sent, and the cap leaves it out (43.182961ms)
✔ clean rebase: applied, the caret survives, the base moves by the rebase POST (4.516342ms)
✔ the block under the caret is the teammate's too, and undo brings back yours (3.271274ms)
✔ typing mid-flight: the merge is not applied and the base does not move (1.337629ms)
✔ a merge the editor cannot represent stops after three tries (4.982017ms)
✔ a conflict is shown, locks the editor's own commits, and Resolve settles it (1.507064ms)
✔ leaving: a conflict stays with the choice; a failed flush offers Leave anyway; a stored draft leaves (1.941829ms)
✔ a stale tab shows the newer draft, offered, and never overwrites it (1.185758ms)
✔ the first scratch commit: empty creates nothing, then one page, then drafts on it (1.015823ms)
✔ noBase and gone lead to the existing choices (1.039798ms)
✔ a commit that merged is applied when nothing was typed since (1.328914ms)
✔ back from the cache: nothing unsaved reloads, unsaved text autosaves at once (7.734819ms)
✔ an own draft committed meanwhile goes on as a new draft (1.296193ms)
✔ a reload keeps a stored draft; unsent text still commits (0.488486ms)
✔ a page deleted mid-edit: what is typed is still stored as the draft, and nothing commits (H1) (0.981559ms)
✔ an offered draft committed in another tab: typing goes on as a new draft (H1) (2.392675ms)
✔ a commit reply without a revision is not a commit; an emptied day starts afresh (H2) (1.24633ms)
✔ Resolve stores what was typed first, and takes no typing until its answer is applied (M1) (4.170861ms)
✔ closing with a choice open, or commits held, still writes the text, never commits (M2) (0.976079ms)
✔ closing inside the settling window sends the loaded version with settling=1 (M3) (0.323039ms)
✔ a clean merge not applied because of typing still ends the choice on show (M4) (0.815863ms)
✔ settling finds the draft committed with a teammate's text: a close still writes (M-A) (0.433564ms)
✔ settling finds another tab's newer draft: the tab shows it before any typing (0.543648ms)
✔ a page deleted before the first autosave: the text is offered as a scratch page, and a close makes one (M-B) (0.56106ms)
✔ an autosave that never answered but landed: its 409 keeps the typing since (L3) (0.508303ms)
✔ marks: em outside strong, bold reopened around italics, edges outside (8.736196ms)
✔ marks close before code, links and atoms, and reopen after (0.548346ms)
✔ untouched blocks and atoms re-emit their source; edited atoms are written from attributes (8.224697ms)
✔ empty blocks are written as nothing (3.341826ms)
✔ an unclosed fence that is no longer last gets its closing fence (3.353015ms)
✔ the structure check puts Join's seam where a kept one would merge two blocks (2.825377ms)
✔ prepareSave adopts the parse when no seam or rewrite can save the document (3.74915ms)
✔ reparse: typed emphasis becomes a mark, "- " after a break becomes an item (3.986962ms)
✔ a trailing hard break stays on screen and is written as nothing (1.204352ms)
✔ the reparse waits while an IME is composing (1.276085ms)
✔ copied blocks paste with their bytes and seams; a cut and paste gives the body back (5.312637ms)
✔ a forged x-mapa slice is refused, and text from outside is read as Markdown (0.697814ms)
✔ rebuild changes origins only, outside undo history (3.57125ms)
✔ applyBody takes a teammate's block, keeps the caret, and ends untouched (2.538667ms)
✔ a block whose context changed is written again: a task toggled, a bullet, a quote (2.122996ms)
✔ a duplicate ^id typed above its holder never takes the id from it (0.984605ms)
✔ a copy-dragged block is reparsed, and says what its Markdown says (1.117691ms)
✔ a history command that throws is refused, never thrown (4.790199ms)
✔ an image re-emits its source, and an edited alt changes only its span (1.72093ms)
✔ a paste whose image copy is refused says why and pastes nothing (15.829835ms)
✔ a line of image openers reads in linear time (104.173304ms)
✔ a line of shared link address reads in linear time (12.819113ms)
✔ a line of shared web address reads in linear time (56.191596ms)
✔ one rename at a time, from either field (2.175142ms)
✔ an empty or unchanged title sends nothing (0.202325ms)
✔ a refusal keeps what was typed, and the title (0.225668ms)
✔ the pending state holds for the busy rule (7.89826ms)
✔ a failed POST says so and keeps the title (0.919885ms)
✔ Update links posts the confirm page's POST (0.27529ms)
✔ clean is CleanTitle's whitespace rule (0.324301ms)
✔ the saver's base follows a rename made over it, and only that (0.311317ms)
✔ closing sends the rename as one keepalive POST (2.916998ms)
✔ the port answers every shared case as typeddate.go does (8.99212ms)
✔ numbers follow the locale: 12/11 is November in en-IE, December in en-US (0.257347ms)
✔ M6: several files land in the order they were chosen (42.121704ms)
✔ M5: one Backspace before the box keeps the image where the box is (12.384338ms)
✔ M5: undoing text typed just before the box keeps the upload (13.231417ms)
✔ L12: a failed upload an undo takes away does not stall the next (14.804495ms)
✔ M4: Replace… keeps the old image until the new one is in, and its alt (14.827337ms)
✔ M3 and N1: text wins, except over a picture copied from a page (1.365662ms)
✔ N2: a JPEG over 10 MB is scaled before its size is checked (10.723648ms)
✔ a drag whose anchor the document no longer reaches selects to its end (6.7109ms)
ℹ tests 143
ℹ suites 0
ℹ pass 143
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 8445.67432
=== vet ===
go vet ./...
go vet -tags browser ./internal/mapatest/
=== fmt ===
=== code ===
go tool rastrillo budget code
The base has no .rastrillo/code.txt: skipping the check that records only go down.
budget code: within the limits.
=== test ===
CGO_ENABLED=0 go test ./...
? amadan.net/oficina/mapa/cmd/mapa [no test files]
ok amadan.net/oficina/mapa/internal/mapa 4.374s
ok amadan.net/oficina/mapa/internal/mapa/emoji (cached)
? amadan.net/oficina/mapa/internal/mapa/icons [no test files]
ok amadan.net/oficina/mapa/internal/mapa/imagefile (cached)
ok amadan.net/oficina/mapa/internal/mapa/locale (cached)
ok amadan.net/oficina/mapa/internal/mapa/markup 0.127s
ok amadan.net/oficina/mapa/internal/mapa/notionmd 0.281s
ok amadan.net/oficina/mapa/internal/mapa/seal (cached)
ok amadan.net/oficina/mapa/internal/mapatest 13.820s
? amadan.net/oficina/mapa/scripts/mutate [no test files]
? amadan.net/oficina/mapa/scripts/preview [no test files]
=== migration-check ===
go tool rastrillo migration check
rastrillo migration check: models and migrations agree
=== credits-check ===
python3 scripts/credits.py --check
credits: checked
diff --git a/AGENTS.md b/AGENTS.md| index 8d248cd..5d0e154 100644 |
| --- a/AGENTS.md |
| +++ b/AGENTS.md |
| @@ -173,6 +173,12 @@ Makefile, estilo's files served straight from the module). |
| `import_pins.go` (the import pins its roots once, marked in the |
| sealed coordinate). Pins hold up to 20 (`pins.go` still reads a |
| list sealed at 12). |
| + - The importer's looks (the same spec, §6.1, §6.4, phase 4): |
| + `import_looks.go` (a page's icon and cover prepared before its |
| + write, under notion_images' pseudo-blocks `icon:` and `cover:`; |
| + covers fetched only from Notion's file store and its cover gallery, |
| + the one external path the notion module pins), and `ImportUpdate`'s |
| + styled revision between the renamed and the edited. |
| - `internal/mapatest/` — the gates of spec §11, from the outside. |
| `browser_test.go` is behind the `browser` tag. |
| - `scripts/preview/`, `scripts/mutate/` — `make preview`, `make mutate`. |
| @@ -212,7 +218,7 @@ Makefile, estilo's files served straight from the module). |
| (L9, level-up build note 79), that Recently edited filters team |
| pages inside its query (build note 80), the images' named risks |
| (`scripts/mutate/images.go`), and that the Notion import's gates I1 |
| - to I19 can (`MUTATE_GATES=I3,I13` runs a few). |
| + to I25 can (`MUTATE_GATES=I3,I13` runs a few). |
| ## Serving |
diff --git a/copy-review/import-looks/result.json b/copy-review/import-looks/result.json| new file mode 100644 |
| index 0000000..6f443b9 |
| --- /dev/null |
| +++ b/copy-review/import-looks/result.json |
| @@ -0,0 +1,53 @@ |
| +{ |
| + "action": "approve", |
| + "guidance": null, |
| + "note": "Reviewed 2026-11-22 by Luna (gpt-5.6-luna through Codex). Luna's edits are applied: the report says Banners, Mapa's word, for what Notion calls covers.", |
| + "not_applied": [], |
| + "strings": [ |
| + { |
| + "id": "report.icons", |
| + "text": "Icons imported", |
| + "was": null |
| + }, |
| + { |
| + "id": "report.icons.not", |
| + "text": "Icons not imported", |
| + "was": null |
| + }, |
| + { |
| + "id": "report.covers", |
| + "text": "Banners imported", |
| + "was": "Covers imported" |
| + }, |
| + { |
| + "id": "report.covers.not", |
| + "text": "Banners not imported", |
| + "was": "Covers not imported" |
| + }, |
| + { |
| + "id": "look.emoji", |
| + "text": "not in Mapa's emoji list", |
| + "was": "an emoji Mapa doesn't have" |
| + }, |
| + { |
| + "id": "look.iconset", |
| + "text": "from Notion's icon set or another website", |
| + "was": null |
| + }, |
| + { |
| + "id": "look.elsewhere", |
| + "text": "from another website", |
| + "was": null |
| + }, |
| + { |
| + "id": "look.iconlarge", |
| + "text": "too large for an icon (over 128 KB or 512 pixels on a side)", |
| + "was": "too large for an icon (over 128 KB or 512 pixels)" |
| + }, |
| + { |
| + "id": "loss.widths", |
| + "text": "Column widths", |
| + "was": null |
| + } |
| + ] |
| +} |
| \ No newline at end of file |
diff --git a/copy-review/import-looks/strings.json b/copy-review/import-looks/strings.json| new file mode 100644 |
| index 0000000..2d30666 |
| --- /dev/null |
| +++ b/copy-review/import-looks/strings.json |
| @@ -0,0 +1,74 @@ |
| +[ |
| + { |
| + "id": "report.icons", |
| + "section": "Import report", |
| + "label": "report.icons", |
| + "text": "Icons imported", |
| + "context": "A row label in the import report's detail list: how many Notion page icons became Mapa page icons. A number follows.", |
| + "notes": "" |
| + }, |
| + { |
| + "id": "report.icons.not", |
| + "section": "Import report", |
| + "label": "report.icons.not", |
| + "text": "Icons not imported", |
| + "context": "Row label: page icons not brought across, by reason ('reason: count; reason: count'), or 0.", |
| + "notes": "" |
| + }, |
| + { |
| + "id": "report.covers", |
| + "section": "Import report", |
| + "label": "report.covers", |
| + "text": "Covers imported", |
| + "context": "Row label: how many Notion page covers became Mapa page banners. A number follows.", |
| + "notes": "" |
| + }, |
| + { |
| + "id": "report.covers.not", |
| + "section": "Import report", |
| + "label": "report.covers.not", |
| + "text": "Covers not imported", |
| + "context": "Row label: page covers not brought across, by reason, or 0.", |
| + "notes": "" |
| + }, |
| + { |
| + "id": "look.emoji", |
| + "section": "Import report", |
| + "label": "look.emoji", |
| + "text": "an emoji Mapa doesn't have", |
| + "context": "A reason in the Notion import's report, after 'Icons not imported:' or 'Covers not imported:', followed by ': <count>'. Several reasons are joined with '; '. The page's Notion icon is an emoji outside Mapa's emoji list.", |
| + "notes": "" |
| + }, |
| + { |
| + "id": "look.iconset", |
| + "section": "Import report", |
| + "label": "look.iconset", |
| + "text": "from Notion's icon set or another website", |
| + "context": "A reason in the Notion import's report, after 'Icons not imported:' or 'Covers not imported:', followed by ': <count>'. Several reasons are joined with '; '. The icon is one of Notion's own built-in icons (SVG, which Mapa refuses) or a picture at another web address, which the import never fetches.", |
| + "notes": "" |
| + }, |
| + { |
| + "id": "look.elsewhere", |
| + "section": "Import report", |
| + "label": "look.elsewhere", |
| + "text": "from another website", |
| + "context": "A reason in the Notion import's report, after 'Icons not imported:' or 'Covers not imported:', followed by ': <count>'. Several reasons are joined with '; '. A cover that is a picture at another web address (Unsplash and the like), which the import never fetches. Notion's own cover gallery is fetched.", |
| + "notes": "" |
| + }, |
| + { |
| + "id": "look.iconlarge", |
| + "section": "Import report", |
| + "label": "look.iconlarge", |
| + "text": "too large for an icon (over 128 KB or 512 pixels)", |
| + "context": "A reason in the Notion import's report, after 'Icons not imported:' or 'Covers not imported:', followed by ': <count>'. Several reasons are joined with '; '. The uploaded icon or custom emoji is over the icon limits. In Mapa the person can upload a smaller one, which Mapa's picker scales.", |
| + "notes": "" |
| + }, |
| + { |
| + "id": "loss.widths", |
| + "section": "Import report", |
| + "label": "loss.widths", |
| + "text": "Column widths", |
| + "context": "A row in the import report's list of things Notion had that Mapa does not keep, followed by a count: Notion columns of different widths become Mapa columns of equal width.", |
| + "notes": "" |
| + } |
| +] |
| \ No newline at end of file |
diff --git a/docs/superpowers/specs/2026-11-17-notion-import.md b/docs/superpowers/specs/2026-11-17-notion-import.md| index 14dfb83..5c6d856 100644 |
| --- a/docs/superpowers/specs/2026-11-17-notion-import.md |
| +++ b/docs/superpowers/specs/2026-11-17-notion-import.md |
| @@ -249,7 +249,7 @@ The run's report is for importers only. It unseals titles to show them. |
| - Its body is the mapped blocks (§10), with the parent line first (§9.4). |
| - Its title is the Notion title, made to fit (§9.2). |
| - Its sealed record carries the Notion times (§14). |
| -- The page's icon and cover are not imported. They are counted. |
| +- The page's icon and cover are imported as its look (columns and icons spec §6.1). An icon or cover Mapa cannot hold is counted. *(Amended by the columns and icons spec, `2026-11-22-mapa-columns-icons.md`, §6.6.)* |
| - Notion returns at most 25 mentions inside a title on the page object. A title at that limit is read in full from the page property endpoint (`GET /v1/pages/{id}/properties/title`), which M4's path pin allows. |
| ### 9.2 Titles |
| @@ -316,7 +316,10 @@ Mapa has no tree. Notion's tree becomes links, both ways: |
| | `code` | a fence: ```` ``` ```` plus the language (lowercased, spaces to `-`; `plain text` gives none). If the code holds a line starting ```` ``` ```` after any leading spaces (the closing test trims them all: `blocks.go`, and `markup.mjs`'s port), the fence is `~~~`. If it holds both, the block is written as a placeholder with the code in it (counted). The caption, if any, follows as an `*italic*` paragraph | — | |
| | `divider` | `---` | — | |
| | `table`, `table_row` | pipe-table text, one paragraph: a header row, a `\| --- \|` row when Notion marks a header, then one line per row. Mapa shows it as lines of text (level-up D10); a future vault export (base decision 15, not built) would render it as a table. A cell's line breaks become spaces; a `\|` inside a cell becomes `/` | layout, column and row header styling. A table that needs sorting or typed columns belongs in Fichas | |
| -| `column_list`, `column` | each column's blocks in order, left to right | side-by-side layout (counted) | |
| +| `column_list`, `column`, two to four columns | a column layout (columns and icons spec §1): `:::: columns`, each column as `::: column` … `:::` holding its blocks in order, then `::::` | the widths, when they differ (counted) | |
| +| `column_list` with one column | its blocks, in place | — | |
| +| `column_list` with five or more columns | each column's blocks in order, left to right | side-by-side layout (counted) | |
| +| `column_list` inside a column, at any depth | its columns' blocks in order, inside the outer column | the inner layout (counted) | |
| | `tab` (a tabbed container) | each tab in order: its label as a `**bold**` paragraph, then its blocks | the tabs (counted) | |
| | `synced_block`, original | its children, in place | that it is synced (counted) | |
| | `synced_block`, copy | the original's children, in place. **Unverified:** Notion's reference says a copy's children "will be mirrored", and does not say what reading a copy's children returns. The mapper reads the copy's children, and if that is empty or 404s, reads the original's (`synced_from.block_id`). If the original is not shared, a placeholder. §19 step 3 checks against a recording | that it is synced; each copy is its own text from now on (counted) | |
| @@ -396,6 +399,8 @@ Each placeholder's Notion id is recorded, sealed, on the ledger row, so phase 2 |
| ### 11.4 Literal text Mapa would read as markup (D16) |
| +*Amended by the columns and icons spec §6.6: a fence line (`markup.FenceLike`: `:::` after any spaces) is checked on every line, the first and every hard-break continuation, and written with U+200B before its first `:`.* |
| + |
| Mapa has **no escapes** (level-up D11). The editor accepts that because a person typing `*word*` sees what it becomes. An import has nobody watching, and Notion text that discusses Markdown or code is ordinary. Left alone, a Notion line beginning ```` ``` ```` would open a fence that runs to the end of the page (`markup/blocks.go`: an unclosed fence has no end), and two stray backticks would pair up and swallow a link between them (`markup/spans.go`, `codeSpan`). |
| **"Meant" is computed first.** Before writing a block, the mapper decides what it means: the block's kind and level, its task box if it is a to-do, its lines, and its inline parts (literal text, marks, links, mentions, code spans). The check (D9) compares `markup.Parse`, `markup.Spans` and the task box (`render.go`'s `taskBox`) of the written block with that, part for part. Literal text must parse as literal text. |
| @@ -524,7 +529,7 @@ The import writes pages only through two methods in package `mapa`, each **one ` |
| ## 15. Sealing |
| -**New purposes:** `notion.token`, `notion.workspace` (its name and id), `notion.coordinate` (a row's Notion id, its Mapa page id, the revision the import last wrote, the ids it mentioned that were not imported, its placeholders' ids), `notion.staged` (a surveyed tree), `notion.image` (an image block's id, its file's key (§25 note 17) and Mapa image). Print keys are derived apart, as base build note 21 does: `oficina/mapa:print:notion.page` and `…:notion.image`. |
| +**New purposes:** `notion.token`, `notion.workspace` (its name and id), `notion.coordinate` (a row's Notion id, its Mapa page id, the revision the import last wrote, the ids it mentioned that were not imported, its placeholders' ids, and, for a root of the import, its sealed `pin` mark: columns and icons spec §6.3), `notion.staged` (a surveyed tree), `notion.image` (an image block's id, its file's key (§25 note 17) and Mapa image). Print keys are derived apart, as base build note 21 does: `oficina/mapa:print:notion.page` and `…:notion.image`. |
| **New tables and their plaintext,** to be added to base §4's list and to `plaintext_test.go` with the build: |
| @@ -533,7 +538,7 @@ The import writes pages only through two methods in package `mapa`, each **one ` |
| | `notion_connections` (one row) | `id`, `created_by` (member id), `created_at`, `verified_at` | token, workspace name | that a Notion connection exists, who made it, when it was last checked | |
| | `notion_runs` | `id`, `actor`, `state`, `lease` (random, redrawn on start, resume and Stop), `started_at`, `heartbeat_at`, `progress_at`, `finished_at`, the counters, `error_code` | — | when imports ran, who ran them, how many pages each created, kept, failed. The lease is random and says nothing | |
| | `notion_pages` (the map) | `id`, `notion_print` (unique), `state`, `error_code`, `surveyed_run`, `seen_run` | the coordinate record (Notion id, last Notion title, Mapa page id, last written revision, unresolved mention ids, placeholder ids); the staged tree | how many Notion pages exist and their states | |
| -| `notion_images` | `id`, `place_print` (unique: an HMAC of the Notion block id and the **Notion** page id together, which the map pins to one Mapa page; §25.7), `block_print` (an HMAC of the block id alone, not unique, to find a block that moved or is shown on several pages), `state` (`imported`, `refused`; a transient failure keeps no row, so the next run tries again) | the image record (block id, the file's key (§25 note 17), Mapa page id, public id, refusal reason) | how many images were imported, refused and failed, and, through equal `block_print`s, how many Notion images appear on more than one page. The images spec's own `images` table holds the rest (§12) | |
| +| `notion_images` | `id`, `place_print` (unique: an HMAC of the Notion block id and the **Notion** page id together, which the map pins to one Mapa page; §25.7; and one row each for a page's icon and cover, whose place print is an HMAC in a domain of its own (`look`, the Notion page id and the pseudo-block `icon:` or `cover:`), and whose `block_print` is the same value, so a look row shares no print with any other row: columns and icons spec §6.1; the table's row count, plaintext, includes them), `block_print` (an HMAC of the block id alone, not unique, to find a block that moved or is shown on several pages), `state` (`imported`, `refused`; a transient failure keeps no row, so the next run tries again) | the image record (block id, the file's key (§25 note 17), Mapa page id, public id, refusal reason) | how many images were imported, refused and failed, and, through equal `block_print`s, how many Notion images appear on more than one page. The images spec's own `images` table holds the rest (§12) | |
| - **What the file still shows, said plainly.** The coordinate is sealed, so no column joins a ledger row to a Mapa page. **But the plaintext event log does.** A run's `created` events, by the run's actor, inside the run's window in `notion_runs`, mark which team pages it made, and sequential `pages.id` and `notion_pages.id` in survey order line them up row for row. So the file shows **which team pages came from a Notion import, and roughly their order in Notion**. It does not show their titles, bodies or Notion ids. This goes in the leak list. `notion_pages` carries no `updated_at`, which would be a second join. |
| - **Prints are HMACs under the instance key**, equality only, as every print in Mapa (base §4). |
diff --git a/docs/superpowers/specs/2026-11-22-mapa-columns-icons.md b/docs/superpowers/specs/2026-11-22-mapa-columns-icons.md| index f279c46..8ae4f2c 100644 |
| --- a/docs/superpowers/specs/2026-11-22-mapa-columns-icons.md |
| +++ b/docs/superpowers/specs/2026-11-22-mapa-columns-icons.md |
| @@ -793,3 +793,14 @@ Fable found every round-1 finding answered in substance, and five mediums and si |
| - **P7, Fable on the build, round 1 (`0b7cf66`), CHANGES REQUIRED with no High.** Answered: list ids that a script toggle could repeat (M1), the wrong row swapped for a page shown twice (M2), `aria-current` doubled or lost after a toggle (M3), → and ← (M4), the gates above (M5), a failed parent's children taken for roots (M6), a root already pinned reported as having no slot (M7); lows 8, 10 to 17. Not done: low 9, the report's "your" for an importer who is not the run's actor: the marks do not record whose sidebar took the pins, and Resume by another member is rare. |
| - **P8, Fable's round 2 (`8585b08`): APPROVE, no High or Medium.** Its lows answered: arrow toggles go one after another, so two rows opened quickly both stay open (L1); a reply takes focus back only when it was not moved elsewhere (L2); a reply that is not a page back where the person is reloads instead (L3); the report's four sentences are gated (L4); an open row past the 200-row cap is drawn open with only its link to all its pages, so its arrow still closes it (L5); two loose assertions tightened (L6). |
| +### Phase 4: the importer's icons, covers and widths (`feat/import-looks`, and the notion module's `feat/looks`) |
| + |
| +- **F1, the module.** `Icon.URL` (file, external, custom_emoji), `Page.Cover {Type, URL}` in place of `HasCover`, and `Block.WidthRatio`, each read from Notion's documented shapes (`notiontest.AddLooks`, `TestPageLooksDecode`); no real recording was made, as §6.5's unverified points (a custom emoji's host, `width_ratio` on a column read, and whether the gallery answers without a redirect, which the fetcher refuses) await §19's first real run, listed in the module's AGENTS.md. Q5: the file transport pins `www.notion.so` to `/images/page-cover/` and one plain name after it (a leaf pair: no `%`, no further `/`), and `Files.Gallery` answers for that pair alone; M5 refuses every other path on that host, encoded slashes and backslashes included, and three mutations (the pair removed, the host pinned alone, the leaf rule removed) are caught. |
| +- **F2, the staged tree.** `notionmd.Page` holds the look under new keys (`pageIcon`, `pageCover`), so a tree staged before this decodes with none, and that page's look comes on its next run. The mapper writes nothing of the look and no longer counts it; it counts `column_widths` when a layout's columns' ratios differ (a column with none is an even share). |
| +- **F3, the look before the write.** `import_looks.go` prepares the icon and the cover after the page's images and before its transaction, under §12's rules: the page object read again for a fresh URL, the lease checked before each add, a refusal the page's count and never its failure. An emoji goes through `EmojiIcon`'s check. An icon is fetched with a 128 KiB cap, and one over 512 pixels a side is discarded at once and remembered as refused. A cover is fetched when it is Notion-hosted or on the gallery's pair. The page object is read again once a page, and what it holds now is checked as Survey's was. A passing failure (not a permanent refusal) keeps the icon or banner the page has, so it costs no revision now and none to undo next run. The look's places are printed in a domain of their own (`look`, the page, the pseudo-block), so a look row shares no print with a block's. The look's added images and places join the page's images, so a kept or failed page discards them and a written page keeps their `notion_images` rows in its own transaction. |
| +- **F4, the writes.** `ImportCreate` writes the record with its icon and banner (centred, `Y: 50`), and its commit attaches them. `ImportUpdate` writes renamed, styled, edited, each only when needed, in one transaction (`update:styled` is a new crash point); the styled revision carries drafts as a rename's does. "Unchanged" compares the look too. A page this run prepared no look for (a fix-up after a Resume) keeps its own. |
| +- **F5, the report.** "Icons imported", "Icons not imported" by reason, "Banners imported" and "Banners not imported" (Luna: Mapa's word for what Notion calls a cover), and "Column widths" among the losses; the old "Page icons" and "Page covers" losses are gone (an old run's report shows them by key). Luna's wording applied (`copy-review/import-looks`). |
| +- **F6, gates.** I20 and I25 (`TestI20IconsAreImported`: emoji, custom emoji and uploaded icons imported; Notion's set, an emoji Mapa lacks, an icon too wide, a download that fails and a custom emoji on an unpinned host counted, the page written each time); I21 (`TestI21CoversAreImportedFromThePinOnly`); I22 is COL11 plus the width goldens; I24 (`TestI24ALookChangedInNotionIsStyled`, `TestI24RenamedStyledEditedInOrder`, and I17's re-run crash case now renaming, restyling and editing at every crash point). Seven mutations, all caught. The import spec's §9.1, §10, §11.4 and §15 say what this spec changed. |
| +- **F7, Fable on the build (`bd3ee46`, module `d36f6e0`): APPROVE, no High, two Mediums, answered.** M1: the gallery pin let an encoded `/` or `\` follow its prefix; it is now a leaf pair. M2: an imported styled revision read "Updated from Notion · edited there <date>", a stale date; it now reads the look's own words with "(from Notion)". Lows: the redirect check added to the first-run list (L1); `Files.Gallery` for covers (L2); the fresh object's types checked (L3); look prints in their own domain (L4); width ratios compared with each other (L5); mutations for the 512-pixel discard, the 128 KiB cap and a fix-up keeping its look, with a Resume test (L6); a passing failure keeps the look (L7); the page object read once (L8); the module lands first and Mapa is pinned to its main before landing (L9). I24 gains the fix-up and passing-failure tests; I20 a 128 KiB icon. |
| +- **F8, Fable's re-check (`4a63cc3`, module `9de0941`): APPROVE, no High or Medium.** Its lows answered: a passing failure keeps the look's `notion_images` row as it was, so a Notion that goes back to that file reuses it; a gallery name starts with a letter or digit; a test that a look's prints meet no block's. F7's L9 is the landing order. |
| + |
diff --git a/go.mod b/go.mod| index 7c11c8c..f0a52c5 100644 |
| --- a/go.mod |
| +++ b/go.mod |
| @@ -6,7 +6,7 @@ toolchain go1.26.11 |
| require ( |
| amadan.net/oficina/estilo.git v0.0.0-20261118055615-d004805f40f2 |
| - amadan.net/oficina/notion.git v0.0.0-20261122111155-169302d88bbe |
| + amadan.net/oficina/notion.git v0.0.0-20261122204613-b8398e79991e |
| amadan.net/rastrillo/rastrillo v0.35.1-0.20261116213651-96812beacacc |
| github.com/chromedp/cdproto v0.158.6 |
| github.com/chromedp/chromedp v0.21.0 |
diff --git a/go.sum b/go.sum| index 1ba473a..76bf4e1 100644 |
| --- a/go.sum |
| +++ b/go.sum |
| @@ -2,6 +2,12 @@ amadan.net/oficina/estilo.git v0.0.0-20261118055615-d004805f40f2 h1:E2+IhBdGcjhX |
| amadan.net/oficina/estilo.git v0.0.0-20261118055615-d004805f40f2/go.mod h1:2UFIFrbTrhew8EFM0C94WmTo2OASM2pHEgT4jzeE/s8= |
| amadan.net/oficina/notion.git v0.0.0-20261122111155-169302d88bbe h1:rTQZz9FJ7tQ7p5adMGNzjFLg6hpplF2NQewgtaQs3ac= |
| amadan.net/oficina/notion.git v0.0.0-20261122111155-169302d88bbe/go.mod h1:2WuyjBTLHwurTGri00zfPxSKc9b3pomdT6wSs/UIvA4= |
| +amadan.net/oficina/notion.git v0.0.0-20261122193726-d36f6e0f6101 h1:EdCkiWKC2PrZuiFEIeSrT4YH3E2Js4d1PKI37kG1qZ8= |
| +amadan.net/oficina/notion.git v0.0.0-20261122193726-d36f6e0f6101/go.mod h1:2WuyjBTLHwurTGri00zfPxSKc9b3pomdT6wSs/UIvA4= |
| +amadan.net/oficina/notion.git v0.0.0-20261122203529-9de09416b0e5 h1:vtl6aPel2HbTNoUnigTlUjymI5T6HTfzPBHN/mqXKQc= |
| +amadan.net/oficina/notion.git v0.0.0-20261122203529-9de09416b0e5/go.mod h1:2WuyjBTLHwurTGri00zfPxSKc9b3pomdT6wSs/UIvA4= |
| +amadan.net/oficina/notion.git v0.0.0-20261122204613-b8398e79991e h1:p2wjp4sf2tnBn9HQjdRlAxGJpkyCXhcCOZggInenvYc= |
| +amadan.net/oficina/notion.git v0.0.0-20261122204613-b8398e79991e/go.mod h1:2WuyjBTLHwurTGri00zfPxSKc9b3pomdT6wSs/UIvA4= |
| amadan.net/rastrillo/fiesta v1.3.0 h1:7SsHw4aeWPLStR3RHFEEtX4CwqKu+Ig3PgNX8FvD8WM= |
| amadan.net/rastrillo/fiesta v1.3.0/go.mod h1:LpO391W1dIRUxOIKklHm+bGyWXtlFyBRRPQCysb9LjY= |
| amadan.net/rastrillo/rastrillo v0.35.1-0.20261116213651-96812beacacc h1:QakboVkj9nqA6ZaKXeDVXWLPobQSVvd80ic521aA8/U= |
diff --git a/internal/mapa/import_convert.go b/internal/mapa/import_convert.go| index c97c56b..50f3ab8 100644 |
| --- a/internal/mapa/import_convert.go |
| +++ b/internal/mapa/import_convert.go |
| @@ -12,10 +12,17 @@ import ( |
| // stagedPage is a surveyed page in notionmd's tree. |
| func stagedPage(page notion.Page, blocks []notion.Block, parent string, |
| seq int) notionmd.Page { |
| - return notionmd.Page{ID: page.ID, Title: convertRuns(page.Title), |
| + staged := notionmd.Page{ID: page.ID, Title: convertRuns(page.Title), |
| Parent: parent, Created: page.CreatedTime, |
| - Edited: page.LastEditedTime, HasIcon: page.Icon != nil, |
| - HasCover: page.HasCover, Seq: seq, Blocks: convertBlocks(blocks)} |
| + Edited: page.LastEditedTime, Seq: seq, Blocks: convertBlocks(blocks)} |
| + if icon := page.Icon; icon != nil { |
| + staged.Icon = ¬ionmd.Look{Type: icon.Type, Emoji: icon.Emoji, |
| + URL: icon.URL} |
| + } |
| + if cover := page.Cover; cover != nil { |
| + staged.Cover = ¬ionmd.Look{Type: cover.Type, URL: cover.URL} |
| + } |
| + return staged |
| } |
| func convertBlocks(blocks []notion.Block) []notionmd.Block { |
| @@ -35,7 +42,8 @@ func convertBlock(block notion.Block) notionmd.Block { |
| Unsupported: block.UnsupportedType, Text: convertRuns(block.RichText), |
| Caption: convertRuns(block.Caption), Checked: block.Checked, |
| Toggleable: block.Toggleable, Language: block.Language, |
| - Title: block.Title, URL: block.URL, Expression: block.Expression, |
| + WidthRatio: block.WidthRatio, |
| + Title: block.Title, URL: block.URL, Expression: block.Expression, |
| Color: block.Color, Cells: convertCells(block.Cells), |
| SyncedFrom: block.SyncedFrom, |
| OriginalUnshared: block.OriginalUnshared, |
diff --git a/internal/mapa/import_history.go b/internal/mapa/import_history.go| index 9ef25f5..daa2690 100644 |
| --- a/internal/mapa/import_history.go |
| +++ b/internal/mapa/import_history.go |
| @@ -14,7 +14,7 @@ import ( |
| // importedSummary is a version's summary when the import wrote it: |
| // "Imported this from Notion · edited there 12 October 2026" for its |
| // first revision, "Updated from Notion · …" for a later one, and a |
| -// rename's own words with "(from Notion)" after them. |
| +// rename's or a new look's own words with "(from Notion)" after them. |
| func (history *pageHistory) importedSummary(index int, |
| plain string) (string, error) { |
| record, err := history.record(index) |
| @@ -25,7 +25,9 @@ func (history *pageHistory) importedSummary(index int, |
| case VerbCreated: |
| return "Imported this from Notion" + |
| editedThere(history.viewer.Locale, record), nil |
| - case VerbRenamed: |
| + case VerbRenamed, VerbStyled: |
| + // The look changed with no edit there: no "edited there" date, |
| + // which would be the body's (Fable on phase 4, M2). |
| return plain + " (from Notion)", nil |
| } |
| return "Updated from Notion" + |
diff --git a/internal/mapa/import_images.go b/internal/mapa/import_images.go| index 9ca36fe..e4d52d0 100644 |
| --- a/internal/mapa/import_images.go |
| +++ b/internal/mapa/import_images.go |
| @@ -42,6 +42,9 @@ type ImageStore interface { |
| type AddedImage interface { |
| PublicID() string |
| Markdown(alt string) string |
| + // Side is the image's longer side in pixels: an imported icon over |
| + // MaxIconSide is refused (columns and icons spec §6.1). |
| + Side() int |
| } |
| // errNoImageStore is the images spec's ErrNoImageStore, whose sentence |
| @@ -53,6 +56,10 @@ type imageCounts struct { |
| Imported int `json:"imported,omitempty"` |
| Links int `json:"links,omitempty"` |
| Failed map[string]int `json:"failed,omitempty"` |
| + // Icon and Cover are the page's look (columns and icons spec |
| + // §6.1): lookImported, or why not; "" when Notion has none. |
| + Icon string `json:"icon,omitempty"` |
| + Cover string `json:"cover,omitempty"` |
| } |
| // pageImages is one page's prepared images: the line for each hosted |
diff --git a/internal/mapa/import_images_place.go b/internal/mapa/import_images_place.go| index 4f5ee8a..3f6e9fa 100644 |
| --- a/internal/mapa/import_images_place.go |
| +++ b/internal/mapa/import_images_place.go |
| @@ -22,6 +22,9 @@ type placedImage struct { |
| page, block, key string |
| publicID, reason string |
| permanent bool |
| + // look marks an icon's or a cover's place (columns and icons spec |
| + // §6.1), printed in its own domain (lookPrints). |
| + look bool |
| } |
| // imagePlace is a notion_images row's sealed record. Key is the file's |
| @@ -56,6 +59,24 @@ func (store *Store) imagePrints(page, block string) (string, string, |
| return place, alone, err |
| } |
| +// lookPrints are an icon's or a cover's handles: one print, in a domain |
| +// of its own, for both, so a look row never shares a block's place and |
| +// its block print finds no other row (Fable on phase 4, L4). |
| +func (store *Store) lookPrints(page, pseudo string) (string, string, |
| + error) { |
| + place, err := store.sealer.Print(seal.PrintNotionImage, |
| + []byte("look\x00"+notionKey(page)+"\x00"+pseudo)) |
| + return place, place, err |
| +} |
| + |
| +// printsOf is a placed image's handles. |
| +func (store *Store) printsOf(placed placedImage) (string, string, error) { |
| + if placed.look { |
| + return store.lookPrints(placed.page, placed.block) |
| + } |
| + return store.imagePrints(placed.page, placed.block) |
| +} |
| + |
| func (store *Store) openPlace(row NotionImage) (imagePlace, error) { |
| var place imagePlace |
| plain, err := store.sealer.Open(seal.PurposeNotionImage, |
| @@ -66,6 +87,16 @@ func (store *Store) openPlace(row NotionImage) (imagePlace, error) { |
| return place, json.Unmarshal(plain, &place) |
| } |
| +// priorLook is where a page's icon or cover went last time. |
| +func (job *importJob) priorLook(ctx context.Context, page, |
| + pseudo string) (imagePlace, bool, error) { |
| + place, _, err := job.store.lookPrints(page, pseudo) |
| + if err != nil { |
| + return imagePlace{}, false, err |
| + } |
| + return job.placeAt(ctx, place) |
| +} |
| + |
| // priorPlace is where the block went on this page last time. |
| func (job *importJob) priorPlace(ctx context.Context, page, |
| block string) (imagePlace, bool, error) { |
| @@ -73,6 +104,12 @@ func (job *importJob) priorPlace(ctx context.Context, page, |
| if err != nil { |
| return imagePlace{}, false, err |
| } |
| + return job.placeAt(ctx, place) |
| +} |
| + |
| +// placeAt is the notion_images row at a place print, opened. |
| +func (job *importJob) placeAt(ctx context.Context, |
| + place string) (imagePlace, bool, error) { |
| row, found := notionImageOf(job.store.database.WithContext(ctx), place) |
| if !found { |
| return imagePlace{}, false, nil |
| @@ -140,7 +177,7 @@ func keepPlaces(db *gorm.DB, store *Store, pageID int64, |
| func keepPlace(db *gorm.DB, store *Store, pageID int64, |
| placed placedImage) error { |
| - place, alone, err := store.imagePrints(placed.page, placed.block) |
| + place, alone, err := store.printsOf(placed) |
| if err != nil { |
| return err |
| } |
diff --git a/internal/mapa/import_images_store.go b/internal/mapa/import_images_store.go| index 85c49a1..f3e98f6 100644 |
| --- a/internal/mapa/import_images_store.go |
| +++ b/internal/mapa/import_images_store.go |
| @@ -24,6 +24,10 @@ type addedImage struct{ image Image } |
| func (added addedImage) PublicID() string { return added.image.PublicID } |
| +func (added addedImage) Side() int { |
| + return max(added.image.Width, added.image.Height) |
| +} |
| + |
| func (added addedImage) Markdown(alt string) string { |
| return added.image.Markdown(alt) |
| } |
diff --git a/internal/mapa/import_looks.go b/internal/mapa/import_looks.go| new file mode 100644 |
| index 0000000..3ba57d5 |
| --- /dev/null |
| +++ b/internal/mapa/import_looks.go |
| @@ -0,0 +1,276 @@ |
| +package mapa |
| + |
| +import ( |
| + "context" |
| + |
| + "amadan.net/oficina/mapa/internal/mapa/notionmd" |
| + "amadan.net/oficina/notion.git/notion" |
| +) |
| + |
| +// A Notion page's look (columns and icons spec §6.1): its icon and its |
| +// cover, prepared with its images, before the page's transaction, under |
| +// the same rules (import spec §12): a fresh URL from the page object, |
| +// the lease checked just before each add, a failure the page's own |
| +// count and never its failure. notion_images keeps where each went, in |
| +// a print domain of its own (lookPrints), so the file's key decides |
| +// whether it changed, as for an image block. |
| + |
| +// The look's pseudo-blocks in notion_images. |
| +const ( |
| + iconPlace = "icon:" |
| + coverPlace = "cover:" |
| +) |
| + |
| +// The look's outcomes, in words for the report. lookImported counts; |
| +// the rest are why not. |
| +const ( |
| + lookImported = "imported" |
| + lookEmoji = "not in Mapa's emoji list" |
| + lookIconSet = "from Notion's icon set or another website" |
| + lookElsewhere = "from another website" |
| + lookIconLarge = "too large for an icon (over 128 KB or 512 pixels " + |
| + "on a side)" |
| +) |
| + |
| +// pageLook is a page's prepared icon and banner, the images it added, |
| +// where each went, and the page object read again for fresh URLs, once. |
| +type pageLook struct { |
| + icon *Icon |
| + banner *Banner |
| + added []AddedImage |
| + placed []placedImage |
| + fresh *notion.Page |
| +} |
| + |
| +// lookOutcome is one icon's or cover's: the image's public id, or why |
| +// not, and whether that is for good. |
| +type lookOutcome struct { |
| + public, reason string |
| + permanent bool |
| +} |
| + |
| +// prepareLook prepares a page's icon and cover, counting each. |
| +func (job *importJob) prepareLook(ctx context.Context, entry *importEntry, |
| + counts *imageCounts) (*pageLook, error) { |
| + look := &pageLook{} |
| + if err := job.prepareIcon(ctx, entry, look, counts); err != nil { |
| + return nil, err |
| + } |
| + return look, job.prepareCover(ctx, entry, look, counts) |
| +} |
| + |
| +func (job *importJob) prepareIcon(ctx context.Context, entry *importEntry, |
| + look *pageLook, counts *imageCounts) error { |
| + icon := entry.staged.Icon |
| + switch { |
| + case icon == nil: |
| + return nil |
| + case icon.Type == notion.IconEmoji: |
| + made, err := EmojiIcon(icon.Emoji) |
| + if err != nil { |
| + counts.Icon = lookEmoji |
| + return nil |
| + } |
| + look.icon, counts.Icon = made, lookImported |
| + return nil |
| + case !iconFetched(icon.Type): |
| + // Notion's own icon set is SVG, which Mapa refuses, and any |
| + // other address is never fetched (import D13). |
| + counts.Icon = lookIconSet |
| + return nil |
| + } |
| + got, err := job.lookImage(ctx, entry, iconPlace, icon, look) |
| + if err != nil { |
| + return err |
| + } |
| + switch { |
| + case got.reason == "": |
| + look.icon, counts.Icon = &Icon{Image: got.public}, lookImported |
| + case !got.permanent: |
| + // Tried again next run: the page keeps the icon it has, so a |
| + // passing failure is not two revisions (Fable on phase 4, L7). |
| + look.icon, counts.Icon = entry.current.Icon, got.reason |
| + default: |
| + counts.Icon = got.reason |
| + } |
| + return nil |
| +} |
| + |
| +// iconFetched is an icon type whose picture is downloaded. |
| +func iconFetched(kind string) bool { |
| + return kind == notion.IconCustomEmoji || kind == notion.FileHosted |
| +} |
| + |
| +// coverFetched is a cover downloaded: Notion-hosted, or from Notion's |
| +// own gallery, the one external address the module pins for it (Q5). |
| +func (job *importJob) coverFetched(cover *notionmd.Look) bool { |
| + return cover.Type == notion.FileHosted || |
| + (cover.Type == notion.FileExternal && job.files.Gallery(cover.URL)) |
| +} |
| + |
| +func (job *importJob) prepareCover(ctx context.Context, entry *importEntry, |
| + look *pageLook, counts *imageCounts) error { |
| + cover := entry.staged.Cover |
| + if cover == nil { |
| + return nil |
| + } |
| + if !job.coverFetched(cover) { |
| + counts.Cover = lookElsewhere |
| + return nil |
| + } |
| + got, err := job.lookImage(ctx, entry, coverPlace, cover, look) |
| + if err != nil { |
| + return err |
| + } |
| + switch { |
| + case got.reason == "": |
| + // The API gives no position: centred. |
| + look.banner = &Banner{Image: got.public, Y: 50} |
| + counts.Cover = lookImported |
| + case !got.permanent: |
| + look.banner, counts.Cover = entry.current.Banner, got.reason |
| + default: |
| + counts.Cover = got.reason |
| + } |
| + return nil |
| +} |
| + |
| +// lookImage is an icon's or a cover's image: its last place reused when |
| +// Notion still shows the same file and the page still holds the image, |
| +// a permanent refusal remembered, or a fresh download. |
| +func (job *importJob) lookImage(ctx context.Context, entry *importEntry, |
| + pseudo string, given *notionmd.Look, look *pageLook) (lookOutcome, |
| + error) { |
| + placed := placedImage{page: entry.staged.ID, block: pseudo, look: true, |
| + key: notion.FileKey(given.URL)} |
| + prior, found, err := job.priorLook(ctx, entry.staged.ID, pseudo) |
| + if err != nil { |
| + return lookOutcome{}, err |
| + } |
| + if found && sameFile(prior.Key, placed.key) { |
| + if prior.Reason != "" { |
| + placed.reason, placed.permanent = prior.Reason, true |
| + look.placed = append(look.placed, placed) |
| + return lookOutcome{reason: prior.Reason, permanent: true}, nil |
| + } |
| + if entry.place.PageID != 0 && |
| + job.images.Held(ctx, prior.PublicID, entry.place.PageID) { |
| + placed.publicID = prior.PublicID |
| + look.placed = append(look.placed, placed) |
| + return lookOutcome{public: prior.PublicID}, nil |
| + } |
| + } |
| + added, key, why, err := job.addLook(ctx, entry, pseudo, look) |
| + if err != nil { |
| + return lookOutcome{}, err |
| + } |
| + if key != "" { |
| + placed.key = key |
| + } |
| + if why.text != "" { |
| + look.placed = append(look.placed, refused(placed, why, prior)) |
| + return lookOutcome{reason: why.text, permanent: why.permanent}, nil |
| + } |
| + placed.publicID = added.PublicID() |
| + look.added = append(look.added, added) |
| + look.placed = append(look.placed, placed) |
| + return lookOutcome{public: placed.publicID}, nil |
| +} |
| + |
| +// refused is a refused look's place. A passing failure leaves the page |
| +// its look, so the row stays as it was: a Notion that goes back to that |
| +// file reuses it (Fable's re-check of phase 4, low 2). |
| +func refused(placed placedImage, why refusal, prior imagePlace) placedImage { |
| + if !why.permanent && prior.PublicID != "" { |
| + return placedImage{page: placed.page, block: placed.block, |
| + look: true, key: prior.Key, publicID: prior.PublicID} |
| + } |
| + placed.reason, placed.permanent = why.text, why.permanent |
| + return placed |
| +} |
| + |
| +// addLook downloads an icon or a cover and adds it, and answers the key |
| +// of the file it downloaded. An icon over 512 pixels a side is taken |
| +// away again at once: Mapa never decodes pixels, so it cannot scale one |
| +// down (§6.1). |
| +func (job *importJob) addLook(ctx context.Context, entry *importEntry, |
| + pseudo string, look *pageLook) (AddedImage, string, refusal, error) { |
| + if job.imagesStopped == "" { |
| + if err := job.images.Ready(ctx); err != nil { |
| + job.imagesStopped = errNoImageStore.Error() |
| + } |
| + } |
| + if job.imagesStopped != "" { |
| + return nil, "", refusal{text: job.imagesStopped}, nil |
| + } |
| + if err := job.store.bookkeep(ctx, job.lease, noChange); err != nil { |
| + return nil, "", refusal{}, err |
| + } |
| + data, key, why, err := job.downloadLook(ctx, entry.staged.ID, pseudo, |
| + look) |
| + if err != nil || why.text != "" { |
| + return nil, key, why, err |
| + } |
| + if err := job.store.bookkeep(ctx, job.lease, noChange); err != nil { |
| + return nil, "", refusal{}, err |
| + } |
| + added, err := job.images.Add(ctx, job.who, data) |
| + if why = job.storeRefusal(err); why.text != "" { |
| + return nil, key, why, nil |
| + } |
| + if pseudo == iconPlace && added.Side() > MaxIconSide { |
| + if err := job.images.Discard(ctx, job.who, |
| + []AddedImage{added}); err != nil { |
| + return nil, "", refusal{}, err |
| + } |
| + return nil, key, refusal{text: lookIconLarge, permanent: true}, nil |
| + } |
| + return added, key, refusal{}, nil |
| +} |
| + |
| +// downloadLook fetches the icon's or the cover's file, from the page |
| +// object read again for a fresh URL (once a page), through the pinned |
| +// transport. What the fresh object holds is checked as Survey's was: an |
| +// icon or cover changed since to one Mapa does not fetch gives no file |
| +// (Fable on phase 4, L3). |
| +func (job *importJob) downloadLook(ctx context.Context, pageID, |
| + pseudo string, look *pageLook) ([]byte, string, refusal, error) { |
| + if look.fresh == nil { |
| + page, err := job.client.Page(ctx, pageID) |
| + if err != nil { |
| + return nil, "", refusal{text: fetchReason(err)}, finalOnly(err) |
| + } |
| + look.fresh = &page |
| + } |
| + address, limit := job.freshAddress(*look.fresh, pseudo) |
| + if address == "" { |
| + return nil, "", refusal{text: fetchReason(nil)}, nil |
| + } |
| + key := notion.FileKey(address) |
| + data, err := job.files.Fetch(ctx, address, limit) |
| + if err != nil { |
| + large := notion.CodeOf(err) == notion.CodeTooLarge |
| + text := fetchReason(err) |
| + if large && pseudo == iconPlace { |
| + text = lookIconLarge |
| + } |
| + return nil, key, refusal{text: text, permanent: large}, nil |
| + } |
| + return data, key, refusal{}, nil |
| +} |
| + |
| +// freshAddress is the address to fetch from a fresh page object, and |
| +// its cap, or "" when it holds no picture Mapa fetches. |
| +func (job *importJob) freshAddress(page notion.Page, pseudo string) (string, |
| + int64) { |
| + switch { |
| + case pseudo == iconPlace && page.Icon != nil && |
| + iconFetched(page.Icon.Type): |
| + return page.Icon.URL, MaxIconBytes |
| + case pseudo == coverPlace && page.Cover != nil && |
| + job.coverFetched(¬ionmd.Look{Type: page.Cover.Type, |
| + URL: page.Cover.URL}): |
| + return page.Cover.URL, imageCap |
| + } |
| + return "", 0 |
| +} |
diff --git a/internal/mapa/import_looks_test.go b/internal/mapa/import_looks_test.go| new file mode 100644 |
| index 0000000..4d7a33f |
| --- /dev/null |
| +++ b/internal/mapa/import_looks_test.go |
| @@ -0,0 +1,370 @@ |
| +package mapa |
| + |
| +import ( |
| + "bytes" |
| + "image" |
| + "image/color" |
| + "image/png" |
| + "math/rand/v2" |
| + "strings" |
| + "testing" |
| + |
| + "amadan.net/oficina/notion.git/notiontest" |
| +) |
| + |
| +// I20, I21 and I25 (columns and icons spec §6.1, §9): a Notion page's |
| +// icon and cover become its look, through the pinned file transport; |
| +// what Mapa cannot hold is counted, and the page is written without it. |
| + |
| +// widePicture is a PNG of one colour, small in bytes and w×h in pixels. |
| +func widePicture(t *testing.T, width, height int) []byte { |
| + t.Helper() |
| + canvas := image.NewRGBA(image.Rect(0, 0, width, height)) |
| + for column := range width { |
| + for line := range height { |
| + canvas.Set(column, line, color.RGBA{10, 20, 30, 255}) |
| + } |
| + } |
| + var out bytes.Buffer |
| + if err := png.Encode(&out, canvas); err != nil { |
| + t.Fatal(err) |
| + } |
| + return out.Bytes() |
| +} |
| + |
| +// noisyPicture is a PNG of noise, w×h, too large in bytes for an icon |
| +// at 300×300. |
| +func noisyPicture(t *testing.T, width, height int) []byte { |
| + t.Helper() |
| + random := rand.New(rand.NewPCG(1, 2)) |
| + canvas := image.NewRGBA(image.Rect(0, 0, width, height)) |
| + for column := range width { |
| + for line := range height { |
| + canvas.Set(column, line, color.RGBA{uint8(random.IntN(256)), |
| + uint8(random.IntN(256)), uint8(random.IntN(256)), 255}) |
| + } |
| + } |
| + var out bytes.Buffer |
| + if err := png.Encode(&out, canvas); err != nil { |
| + t.Fatal(err) |
| + } |
| + return out.Bytes() |
| +} |
| + |
| +// unhost takes a hosted file away, so its download fails. |
| +func unhost(ws *notiontest.Workspace, url string) { |
| + path := strings.TrimPrefix(url, strings.TrimSuffix( |
| + notiontest.HostedPrefix, "/")) |
| + path, _, _ = strings.Cut(path, "?") |
| + delete(ws.Files, path) |
| +} |
| + |
| +// looksWorld is a workspace with every look AddLooks makes, plus an |
| +// emoji Mapa lacks, an icon too wide, and an icon whose file is gone. |
| +func looksWorld(t *testing.T) (*importWorld, notiontest.Looks) { |
| + ws := notiontest.NewWorkspace("looks") |
| + looks := ws.AddLooks(picture(t, 1), picture(t, 2)) |
| + odd := ws.Page("", notiontest.Text("Odd emoji")) |
| + ws.SetIcon(odd, notiontest.EmojiIcon("A")) |
| + wide := ws.Page("", notiontest.Text("Wide icon")) |
| + ws.SetIcon(wide, notiontest.FileIcon(ws.Host("wide.png", |
| + widePicture(t, 600, 10)))) |
| + heavy := ws.Page("", notiontest.Text("Heavy icon")) |
| + ws.SetIcon(heavy, notiontest.FileIcon(ws.Host("heavy.png", |
| + noisyPicture(t, 300, 300)))) |
| + gone := ws.Page("", notiontest.Text("Lost icon")) |
| + lost := ws.Host("lost.png", picture(t, 3)) |
| + ws.SetIcon(gone, notiontest.FileIcon(lost)) |
| + unhost(ws, lost) |
| + // I25: a custom emoji on a host the transport does not pin. |
| + foreign := ws.Page("", notiontest.Text("Foreign emoji")) |
| + ws.SetIcon(foreign, notiontest.CustomEmojiIcon("far", |
| + "https://example.com/far.png")) |
| + world := newImportWorld(t, ws) |
| + world.useImages() |
| + world.connect(ana) |
| + return world, looks |
| +} |
| + |
| +func (world *importWorld) lookOf(title string) (Page, Record) { |
| + world.t.Helper() |
| + page, record, ok := world.pageTitled(title) |
| + if !ok { |
| + world.t.Fatalf("no page %q", title) |
| + } |
| + return page, record |
| +} |
| + |
| +// I20 and I25, icons: one on a host the transport does not pin is |
| +// refused before dialling, and counted. |
| +// |
| +// Mutation (make mutate): an emoji icon written without the list's |
| +// check. |
| +func TestI20IconsAreImported(t *testing.T) { |
| + world, _ := looksWorld(t) |
| + run := world.importAs(ana) |
| + if run.State != runDone || run.Failed != 0 { |
| + t.Fatalf("the run: %+v", run) |
| + } |
| + if _, record := world.lookOf("Emoji icon"); record.Icon == nil || |
| + record.Icon.Emoji != "🚀" { |
| + t.Errorf("the emoji icon: %+v", record.Icon) |
| + } |
| + for _, title := range []string{"Custom emoji icon", "Uploaded icon"} { |
| + page, record := world.lookOf(title) |
| + if record.Icon == nil || record.Icon.Image == "" { |
| + t.Errorf("%s: icon %+v", title, record.Icon) |
| + continue |
| + } |
| + if attached, _ := world.imagesOf(page.ID); attached != 1 { |
| + t.Errorf("%s: %d images attached", title, attached) |
| + } |
| + } |
| + for _, title := range []string{"Notion icon", "Odd emoji", "Wide icon", |
| + "Heavy icon", "Lost icon", "Foreign emoji"} { |
| + if _, record := world.lookOf(title); record.Icon != nil { |
| + t.Errorf("%s was given an icon: %+v", title, record.Icon) |
| + } |
| + } |
| + if _, pending := world.imagesOf(0); pending != 0 { |
| + t.Errorf("%d images left pending: the wide icon holds none", pending) |
| + } |
| + report, _ := world.store.report(ctx(), run) |
| + want := map[string]int{lookIconSet: 1, lookEmoji: 1, lookIconLarge: 2, |
| + "couldn't be downloaded": 1, "not from Notion's file store": 1} |
| + if report.Icons != 3 || !sameCounts(report.IconFailures, want) { |
| + t.Errorf("the report's icons: %d, %+v", report.Icons, |
| + report.IconFailures) |
| + } |
| +} |
| + |
| +func sameCounts(got []countView, want map[string]int) bool { |
| + if len(got) != len(want) { |
| + return false |
| + } |
| + for _, each := range got { |
| + if want[each.Label] != each.Count { |
| + return false |
| + } |
| + } |
| + return true |
| +} |
| + |
| +// I21 and I25, covers: an uploaded cover and one from Notion's gallery |
| +// become banners, centred; an Unsplash cover is counted, never fetched. |
| +// |
| +// Mutation (make mutate): an external cover fetched without asking the |
| +// pin. |
| +func TestI21CoversAreImportedFromThePinOnly(t *testing.T) { |
| + world, _ := looksWorld(t) |
| + run := world.importAs(ana) |
| + for _, title := range []string{"Uploaded cover", "Gallery cover"} { |
| + _, record := world.lookOf(title) |
| + if record.Banner == nil || record.Banner.Image == "" || |
| + record.Banner.Y != 50 { |
| + t.Errorf("%s: banner %+v", title, record.Banner) |
| + } |
| + } |
| + if _, record := world.lookOf("Unsplash cover"); record.Banner != nil { |
| + t.Errorf("an Unsplash cover was imported: %+v", record.Banner) |
| + } |
| + for _, request := range world.server.Requests() { |
| + if request.File && strings.Contains(request.Path, "unsplash") { |
| + t.Errorf("fetched %s", request.Path) |
| + } |
| + } |
| + report, _ := world.store.report(ctx(), run) |
| + if report.Covers != 2 || !sameCounts(report.CoverFailures, |
| + map[string]int{lookElsewhere: 1}) { |
| + t.Errorf("the report's covers: %d, %+v", report.Covers, |
| + report.CoverFailures) |
| + } |
| + text := world.importPageText() |
| + for _, want := range []string{"Icons imported", "Banners not imported", |
| + lookElsewhere} { |
| + if !strings.Contains(text, want) { |
| + t.Errorf("the report does not say %q", want) |
| + } |
| + } |
| +} |
| + |
| +// I24, re-runs: an unchanged look downloads nothing and writes nothing; |
| +// an untouched page whose Notion icon changed gets one styled revision; |
| +// a page whose icon was changed in Mapa is kept. |
| +// |
| +// Mutation (make mutate): "unchanged" decided without the look. |
| +func TestI24ALookChangedInNotionIsStyled(t *testing.T) { |
| + ws := notiontest.NewWorkspace("rerun") |
| + looks := ws.AddLooks(picture(t, 1), picture(t, 2)) |
| + world := newImportWorld(t, ws) |
| + world.useImages() |
| + world.connect(ana) |
| + world.importAs(ana) |
| + world.server.Reset() |
| + events := world.pageEvents() |
| + if run := world.importAs(ana); run.Updated != 0 || |
| + world.fileRequests() != 0 || world.pageEvents() != events { |
| + t.Fatalf("an unchanged re-run: %+v, %d fetched", run, |
| + world.fileRequests()) |
| + } |
| + ws.SetIcon(looks.Emoji, notiontest.EmojiIcon("🌍")) |
| + ws.SetIcon(looks.Custom, notiontest.EmojiIcon("🎉")) |
| + mine, _ := world.lookOf("Custom emoji icon") |
| + if _, err := world.store.SetLook(ctx(), bo, mine.ID, LookChange{ |
| + SetIcon: true, Icon: &Icon{Emoji: "📌"}}); err != nil { |
| + t.Fatal(err) |
| + } |
| + world.server.Reset() |
| + run := world.importAs(ana) |
| + if run.Updated != 1 || run.Kept != 1 { |
| + t.Fatalf("after Notion's change: %+v", run) |
| + } |
| + page, record := world.lookOf("Emoji icon") |
| + if record.Icon == nil || record.Icon.Emoji != "🌍" { |
| + t.Fatalf("the icon: %+v", record.Icon) |
| + } |
| + world.expectVerbs(page.ID, VerbCreated, VerbStyled) |
| + viewer, _ := world.store.Viewer(ctx(), ana, nil) |
| + list, err := world.store.History(ctx(), viewer, page.ID, 0) |
| + if err != nil || len(list.Versions) != 2 || !strings.HasSuffix( |
| + list.Versions[0].Summary, " (from Notion)") || |
| + strings.Contains(list.Versions[0].Summary, "edited there") { |
| + t.Errorf("the styled revision reads %+v, %v", list, err) |
| + } |
| + if _, record := world.lookOf("Custom emoji icon"); record.Icon == nil || |
| + record.Icon.Emoji != "📌" { |
| + t.Errorf("a page styled in Mapa lost its icon: %+v", record.Icon) |
| + } |
| +} |
| + |
| +// expectVerbs is a page's events' verbs, in order. |
| +func (world *importWorld) expectVerbs(pageID int64, verbs ...string) { |
| + world.t.Helper() |
| + var got []string |
| + world.store.database.Model(&Event{}).Where("object_kind = ? AND "+ |
| + "object_id = ?", ObjectPage, pageID).Order("id").Pluck("verb", &got) |
| + if strings.Join(got, " ") != strings.Join(verbs, " ") { |
| + world.t.Errorf("verbs %v, want %v", got, verbs) |
| + } |
| +} |
| + |
| +// I24's order: a page renamed, restyled and edited in Notion gets the |
| +// three revisions, renamed, styled, edited, in one write. |
| +func TestI24RenamedStyledEditedInOrder(t *testing.T) { |
| + ws := newSmall() |
| + world := newImportWorld(t, ws.Workspace) |
| + world.connect(ana) |
| + world.importAs(ana) |
| + ws.Retitle(ws.equipment, notiontest.Text("Kit")) |
| + ws.SetIcon(ws.equipment, notiontest.EmojiIcon("💻")) |
| + ws.set(ws.equipment, 0, notiontest.Para(notiontest.Text("Phones."))) |
| + world.server.Reset() |
| + if run := world.importAs(ana); run.Failed != 0 || run.Kept != 0 { |
| + t.Fatalf("the re-run: %+v", run) |
| + } |
| + page, record := world.lookOf("Kit") |
| + if record.Icon == nil || record.Icon.Emoji != "💻" || |
| + !strings.Contains(record.Body, "Phones.") { |
| + t.Fatalf("the page: %+v", record) |
| + } |
| + world.expectVerbs(page.ID, VerbCreated, VerbRenamed, VerbStyled, |
| + VerbEdited) |
| +} |
| + |
| +// A fix-up after a Resume rewrites a page that has an icon: the page |
| +// keeps it, with no styled revision (Fable on phase 4, L6). |
| +// |
| +// Mutation (make mutate): lookRecord gives no look when the run |
| +// prepared none. |
| +func TestI24AFixUpAfterAResumeKeepsTheIcon(t *testing.T) { |
| + ws := notiontest.NewWorkspace("fixup") |
| + alpha := ws.Page("", notiontest.Text("Alpha")) |
| + ws.SetIcon(alpha, notiontest.EmojiIcon("🚀")) |
| + beta := ws.Page("", notiontest.Text("Beta")) |
| + ws.Add(alpha, notiontest.Para(notiontest.PageMention(beta, "Beta"))) |
| + world := newImportWorld(t, ws) |
| + world.connect(ana) |
| + lease, err := world.store.StartRun(ctx(), ana, false) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + seen := 0 |
| + importCrash = func(point string) error { |
| + if point == "write:rendered" { |
| + if seen++; seen == 2 { |
| + world.store.CreateTeamPage(ctx(), bo, "Beta", "Bo's.") |
| + return errCrashed |
| + } |
| + } |
| + return nil |
| + } |
| + t.Cleanup(func() { importCrash = nil }) |
| + world.finish(lease, ana) |
| + importCrash = nil |
| + world.store.InterruptRuns(ctx()) |
| + world.resumeIfNeeded(lease) |
| + page, record := world.lookOf("Alpha") |
| + if record.Icon == nil || record.Icon.Emoji != "🚀" || |
| + !strings.Contains(record.Body, "Beta (Notion)") { |
| + t.Fatalf("Alpha after its fix-up: %+v", record) |
| + } |
| + world.expectVerbs(page.ID, VerbCreated, VerbEdited) |
| +} |
| + |
| +// A changed icon whose download fails for now leaves the page with the |
| +// icon it has: no revision now, and none to undo next run (Fable on |
| +// phase 4, L7). |
| +func TestI24APassingFailureKeepsTheIcon(t *testing.T) { |
| + ws := notiontest.NewWorkspace("passing") |
| + page := ws.Page("", notiontest.Text("Iconic")) |
| + first := ws.Host("one.png", picture(t, 1)) |
| + ws.SetIcon(page, notiontest.FileIcon(first)) |
| + world := newImportWorld(t, ws) |
| + world.useImages() |
| + world.connect(ana) |
| + world.importAs(ana) |
| + mine, before := world.lookOf("Iconic") |
| + next := ws.Host("two.png", picture(t, 2)) |
| + ws.SetIcon(page, notiontest.FileIcon(next)) |
| + unhost(ws, next) |
| + world.server.Reset() |
| + if run := world.importAs(ana); run.Updated != 0 || run.Unchanged != 1 { |
| + t.Fatalf("the re-run: %+v", run) |
| + } |
| + if _, after := world.lookOf("Iconic"); after.Icon == nil || |
| + *after.Icon != *before.Icon { |
| + t.Errorf("the icon went from %+v to %+v", before.Icon, after.Icon) |
| + } |
| + world.expectVerbs(mine.ID, VerbCreated) |
| + // Notion goes back to the first file: its row was kept, so nothing |
| + // is downloaded and nothing written (Fable's re-check, low 2). |
| + ws.SetIcon(page, notiontest.FileIcon(first)) |
| + world.server.Reset() |
| + if run := world.importAs(ana); run.Unchanged != 1 || |
| + world.fileRequests() != 0 { |
| + t.Fatalf("back to the first file: %+v, %d fetched", run, |
| + world.fileRequests()) |
| + } |
| + world.expectVerbs(mine.ID, VerbCreated) |
| +} |
| + |
| +// A look's prints are in a domain of their own: an icon's row shares no |
| +// print with a block named "icon:" on the same page, nor any block's |
| +// block print, so no copy is ever taken from it (Fable's re-check of |
| +// phase 4, low 4). |
| +func TestI20LookPrintsAreTheirOwn(t *testing.T) { |
| + world, _ := looksWorld(t) |
| + page := notiontest.ID(7) |
| + lookPlace, lookAlone, err := world.store.lookPrints(page, iconPlace) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + blockPlace, blockAlone, err := world.store.imagePrints(page, iconPlace) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if lookPlace == blockPlace || lookAlone == blockAlone || |
| + lookAlone != lookPlace { |
| + t.Error("a look's prints meet a block's") |
| + } |
| +} |
diff --git a/internal/mapa/import_report.go b/internal/mapa/import_report.go| index b53cc56..f8711cc 100644 |
| --- a/internal/mapa/import_report.go |
| +++ b/internal/mapa/import_report.go |
| @@ -24,10 +24,15 @@ type reportView struct { |
| FailedCodes []countView |
| Images imageCounts |
| ImageFailures []countView |
| - Losses []countView |
| - Fallbacks, Neutralised, Unshared, Notion int |
| - Fitted, Kept, FailedPages, NotFoundPages []reportPage |
| - Placeholders, UnderRow []reportPage |
| + // Icons and Covers are the pages' looks imported, and IconFailures |
| + // and CoverFailures why the rest were not, by reason (columns and |
| + // icons spec §6.1). |
| + Icons, Covers int |
| + IconFailures, CoverFailures []countView |
| + Losses []countView |
| + Fallbacks, Neutralised, Unshared, Notion int |
| + Fitted, Kept, FailedPages, NotFoundPages []reportPage |
| + Placeholders, UnderRow []reportPage |
| // Pinned and Unpinned are the roots this run offered to the |
| // runner's sidebar, read from their sealed pin marks (columns and |
| // icons spec §6.3): pinned, and those that found no free slot. |
| @@ -62,6 +67,7 @@ func (store *Store) report(ctx context.Context, |
| Images: imageCounts{Failed: map[string]int{}}, PinLimit: maxPins} |
| tally := &reportTally{view: view, store: store, ctx: ctx, run: run.ID, |
| losses: map[string]int{}, codes: map[string]int{}, |
| + icons: map[string]int{}, covers: map[string]int{}, |
| byKey: map[string]reportRow{}} |
| opened := make([]reportRow, 0, len(rows)) |
| for _, row := range rows { |
| @@ -87,7 +93,9 @@ type reportTally struct { |
| run int64 |
| losses map[string]int |
| codes map[string]int |
| - byKey map[string]reportRow |
| + // icons and covers count the looks not imported, by reason. |
| + icons, covers map[string]int |
| + byKey map[string]reportRow |
| } |
| func (tally *reportTally) add(entry reportRow) { |
| @@ -170,6 +178,8 @@ func (tally *reportTally) render(place coordinate, page reportPage) { |
| for reason, count := range images.Failed { |
| view.Images.Failed[reason] += count |
| } |
| + tally.look(images.Icon, &view.Icons, tally.icons) |
| + tally.look(images.Cover, &view.Covers, tally.covers) |
| } |
| result := place.Render |
| if result == nil { |
| @@ -231,9 +241,23 @@ func (tally *reportTally) page(place coordinate) reportPage { |
| return out |
| } |
| +// look counts one page's icon or cover: imported, or why not. |
| +func (tally *reportTally) look(outcome string, imported *int, |
| + why map[string]int) { |
| + switch outcome { |
| + case "": |
| + case lookImported: |
| + *imported++ |
| + default: |
| + why[outcome]++ |
| + } |
| +} |
| + |
| func (tally *reportTally) finish() { |
| tally.view.FailedCodes = sortedCounts(tally.codes, nil) |
| tally.view.ImageFailures = sortedCounts(tally.view.Images.Failed, nil) |
| + tally.view.IconFailures = sortedCounts(tally.icons, nil) |
| + tally.view.CoverFailures = sortedCounts(tally.covers, nil) |
| tally.view.Losses = sortedCounts(tally.losses, lossLabel) |
| sort.Strings(tally.view.Databases) |
| } |
| @@ -290,6 +314,7 @@ var blockNames = map[string]string{ |
| var lossLabels = map[string]string{ |
| notionmd.LossToggle: "Toggles opened out", |
| notionmd.LossColumns: "Columns laid out one after another", |
| + notionmd.LossWidths: "Column widths", |
| notionmd.LossTabs: "Tabs laid out one after another", |
| notionmd.LossSynced: "Synced blocks, now separate copies", |
| notionmd.LossIndent: "Indented blocks moved to the left", |
| @@ -303,8 +328,6 @@ var lossLabels = map[string]string{ |
| notionmd.LossMarkStar: "Bold or italic on text holding a *", |
| notionmd.LossMarkLink: "Bold or italic around a link", |
| notionmd.LossCodeFence: "Code with both kinds of fence", |
| - notionmd.LossIcon: "Page icons", |
| - notionmd.LossCover: "Page covers", |
| notionmd.LossFile: "Files not imported", |
| notionmd.LossStartNumber: "List start numbers", |
| notionmd.LossBlockAnchor: "Links to a block, now to its page", |
diff --git a/internal/mapa/import_safety_test.go b/internal/mapa/import_safety_test.go| index 586cb0c..a091275 100644 |
| --- a/internal/mapa/import_safety_test.go |
| +++ b/internal/mapa/import_safety_test.go |
| @@ -40,8 +40,8 @@ func TestI16TheImportOnlyReads(t *testing.T) { |
| // crashPoints is every named point of the run and the two methods. |
| var crashPoints = []string{"survey:read", "survey:walked", |
| "write:rendered", "create:page", "create:title", "write:committed", |
| - "update:renamed", "update:edited", "write:fixed", "pin:marked", |
| - "write:pinned"} |
| + "update:renamed", "update:styled", "update:edited", "write:fixed", |
| + "pin:marked", "write:pinned"} |
| // I17, crash safety (spec §14.1). The process dies between every pair |
| // of statements in the run, ImportCreate and ImportUpdate, at the first |
| @@ -73,6 +73,10 @@ func crashThenResume(t *testing.T, point string, nth int, rerun bool) { |
| world.importAs(ana) |
| ws.set(ws.handbook, 1, notiontest.Para(notiontest.Text("Changed."))) |
| ws.Retitle(ws.equipment, notiontest.Text("Kit")) |
| + // A new icon too, so the styled revision is between the |
| + // renamed and the edited (columns and icons spec I24). |
| + ws.SetIcon(ws.equipment, notiontest.EmojiIcon("💻")) |
| + ws.set(ws.equipment, 0, notiontest.Para(notiontest.Text("Phones."))) |
| } |
| lease, err := world.store.StartRun(ctx(), ana, false) |
| if err != nil { |
diff --git a/internal/mapa/import_set.go b/internal/mapa/import_set.go| index 6fcab1b..341604e 100644 |
| --- a/internal/mapa/import_set.go |
| +++ b/internal/mapa/import_set.go |
| @@ -29,6 +29,9 @@ type importEntry struct { |
| revision int64 |
| result notionmd.Result |
| images *pageImages |
| + // look is the icon and banner this run prepared, or nil when it |
| + // prepared none (a fix-up after a Resume): the page keeps its own. |
| + look *pageLook |
| } |
| // importSet is the run's pages in survey order, and the whole map. |
diff --git a/internal/mapa/import_store.go b/internal/mapa/import_store.go| index 5d940c6..4dab7a6 100644 |
| --- a/internal/mapa/import_store.go |
| +++ b/internal/mapa/import_store.go |
| @@ -26,6 +26,11 @@ type importWrite struct { |
| place coordinate |
| title string |
| body string |
| + // icon and banner are the page's look (columns and icons spec |
| + // §6.1): written by ImportCreate, and by ImportUpdate's styled |
| + // revision when they changed. |
| + icon *Icon |
| + banner *Banner |
| // origin is Notion's created and edited times for the page. |
| origin Origin |
| // pageID and expect are ImportUpdate's: the page, and the revision |
| @@ -60,7 +65,8 @@ func (store *Store) ImportCreate(ctx context.Context, |
| } |
| origin := write.origin |
| page, err = tx.create(KindPage, RungTeam, actor, Record{Title: title, |
| - Body: cleanBody(write.body), Origin: &origin, Imported: true}, |
| + Body: cleanBody(write.body), Origin: &origin, Imported: true, |
| + Icon: write.icon, Banner: write.banner}, |
| actor, VerbCreated, attachOwn(0)) |
| if err != nil { |
| return err |
| @@ -84,7 +90,9 @@ func (store *Store) ImportCreate(ctx context.Context, |
| // not the one the map holds, or it is gone, it returns ErrImportKept and |
| // writes nothing (spec §13.2). A new title is its own revision first, |
| // logged renamed, holding exactly the previous body, with drafts on the |
| -// old revision carried to it; a new body is a second, logged edited. |
| +// old revision carried to it; a new look is the next, logged styled, |
| +// holding the same body (columns and icons spec §6.4); a new body is |
| +// the last, logged edited. |
| func (store *Store) ImportUpdate(ctx context.Context, |
| write importWrite) (Page, error) { |
| title, err := CleanTitle(write.title) |
| @@ -111,6 +119,12 @@ func (store *Store) ImportUpdate(ctx context.Context, |
| if err := crashPoint("update:renamed"); err != nil { |
| return err |
| } |
| + if err := tx.importStyle(&page, &record, actor, write); err != nil { |
| + return err |
| + } |
| + if err := crashPoint("update:styled"); err != nil { |
| + return err |
| + } |
| if err := tx.importEdit(&page, &record, actor, write); err != nil { |
| return err |
| } |
| @@ -155,6 +169,25 @@ func (tx *Tx) importRename(page *Page, record *Record, actor int64, |
| return tx.carryDrafts(page.ID, from, page.Revision) |
| } |
| +// importStyle is the styled revision (columns and icons spec §6.4): |
| +// the new icon and banner over the body as it stands, attaching the |
| +// run's own images, with drafts carried as a rename's are. |
| +func (tx *Tx) importStyle(page *Page, record *Record, actor int64, |
| + write importWrite) error { |
| + next := *record |
| + next.Icon, next.Banner, next.Imported = write.icon, write.banner, true |
| + if sameLook(*record, next) { |
| + return nil |
| + } |
| + from := page.Revision |
| + if err := tx.commit(page, next, actor, VerbStyled, |
| + attachOwn(0)); err != nil { |
| + return err |
| + } |
| + *record = next |
| + return tx.carryDrafts(page.ID, from, page.Revision) |
| +} |
| + |
| func (tx *Tx) importEdit(page *Page, record *Record, actor int64, |
| write importWrite) error { |
| origin := write.origin |
diff --git a/internal/mapa/import_write.go b/internal/mapa/import_write.go| index e9d6aff..9a3cebc 100644 |
| --- a/internal/mapa/import_write.go |
| +++ b/internal/mapa/import_write.go |
| @@ -58,7 +58,7 @@ func (job *importJob) writePage(ctx context.Context, set *importSet, |
| // downloaded for it (Fable L15). |
| return job.outcome(ctx, entry, state, "", storedImages(entry)) |
| } |
| - images, err := job.prepareImages(ctx, entry) |
| + images, err := job.prepare(ctx, entry) |
| if err != nil { |
| return err |
| } |
| @@ -89,6 +89,24 @@ func (job *importJob) writePage(ctx context.Context, set *importSet, |
| return job.outcome(ctx, entry, state, code, images) |
| } |
| +// prepare fetches what a page's write needs: its blocks' images, then |
| +// its look (columns and icons spec §6.1), whose images go where the |
| +// blocks' do: discarded with them, and their places kept with them. |
| +func (job *importJob) prepare(ctx context.Context, |
| + entry *importEntry) (*pageImages, error) { |
| + images, err := job.prepareImages(ctx, entry) |
| + if err != nil { |
| + return nil, err |
| + } |
| + if entry.look, err = job.prepareLook(ctx, entry, |
| + &images.counts); err != nil { |
| + return nil, err |
| + } |
| + images.added = append(images.added, entry.look.added...) |
| + images.placed = append(images.placed, entry.look.placed...) |
| + return images, nil |
| +} |
| + |
| // render renders a page within its budget. |
| func (job *importJob) render(ctx context.Context, set *importSet, |
| entry *importEntry, images *pageImages) (notionmd.Result, error) { |
| @@ -146,7 +164,8 @@ func (job *importJob) commit(ctx context.Context, set *importSet, |
| return job.create(ctx, set, entry, body) |
| } |
| if entry.current.Title == entry.title && |
| - entry.current.Body == cleanBody(body) { |
| + entry.current.Body == cleanBody(body) && |
| + sameLook(entry.current, entry.lookRecord()) { |
| return mapUnchanged, "", nil |
| } |
| return job.update(ctx, set, entry, body) |
| @@ -204,7 +223,18 @@ func (job *importJob) updateOnce(ctx context.Context, entry *importEntry, |
| func (entry *importEntry) wrote(page Page, body string) { |
| entry.place.PageID, entry.place.Revision = page.ID, page.Revision |
| entry.live, entry.revision = true, page.Revision |
| - entry.current = Record{Title: entry.title, Body: cleanBody(body)} |
| + look := entry.lookRecord() |
| + entry.current = Record{Title: entry.title, Body: cleanBody(body), |
| + Icon: look.Icon, Banner: look.Banner} |
| +} |
| + |
| +// lookRecord is the look the run writes for a page: the one it |
| +// prepared, else the page's own (columns and icons spec §6.4). |
| +func (entry *importEntry) lookRecord() Record { |
| + if entry.look == nil { |
| + return Record{Icon: entry.current.Icon, Banner: entry.current.Banner} |
| + } |
| + return Record{Icon: entry.look.icon, Banner: entry.look.banner} |
| } |
| // create writes a new page, taking the next title when a member took |
| @@ -250,8 +280,10 @@ func (job *importJob) writeOf(entry *importEntry, body string) importWrite { |
| if entry.images != nil { |
| place.ImageLines, placed = entry.images.lines, entry.images.placed |
| } |
| + look := entry.lookRecord() |
| return importWrite{lease: job.lease, who: job.who, row: entry.row, |
| place: place, title: entry.title, body: body, |
| + icon: look.Icon, banner: look.Banner, |
| origin: Origin{Source: "notion", Created: entry.staged.Created, |
| Edited: entry.staged.Edited}, |
| pageID: place.PageID, expect: place.Revision, images: placed} |
diff --git a/internal/mapa/markup/testdata/corpus/import.json b/internal/mapa/markup/testdata/corpus/import.json| index 4665ccd..11524ef 100644 |
| --- a/internal/mapa/markup/testdata/corpus/import.json |
| +++ b/internal/mapa/markup/testdata/corpus/import.json |
| @@ -23,6 +23,9 @@ |
| {"name":"import/columns-nested","body":":::: columns\n\n::: column\nIn.\n\nSide.\n\n:::\n\n::: column\nRight.\n\n:::\n\n::::"}, |
| {"name":"import/columns-fence-text","body":":::: columns\n\n::: column\n:::\n\n:::\n\n::: column\n:::: columns\n\n:::\n\n::::"}, |
| {"name":"import/columns-empty","body":":::: columns\n\n::: column\n:::\n\n::: column\nB.\n\n:::\n\n::::"}, |
| +{"name":"import/columns-widths","body":":::: columns\n\n::: column\nNarrow.\n\n:::\n\n::: column\nWide.\n\n:::\n\n::::"}, |
| +{"name":"import/columns-even","body":":::: columns\n\n::: column\nHalf.\n\n:::\n\n::: column\nHalf too.\n\n:::\n\n::::"}, |
| +{"name":"import/columns-equal-ones","body":":::: columns\n\n::: column\nOne.\n\n:::\n\n::: column\nTwo.\n\n:::\n\n::::"}, |
| {"name":"import/tabs","body":"**First tab**\n\nIn it."}, |
| {"name":"import/synced","body":"Synced text.\n\nMirrored."}, |
| {"name":"import/synced-unshared","body":"> From Notion: a synced block whose original wasn't shared with the import."}, |
diff --git a/internal/mapa/markup/testdata/editor.json b/internal/mapa/markup/testdata/editor.json| index 92b1356..20d6a1a 100644 |
| --- a/internal/mapa/markup/testdata/editor.json |
| +++ b/internal/mapa/markup/testdata/editor.json |
| @@ -1,4 +1,4 @@ |
| -{"clean":"b0d984ce1f956c774f79a321085144ac52a390607557172fc2428e00675f1e4e","bodies":[ |
| +{"clean":"f7c2a5944006373dafcf324c3bed5033ddc528fcdcde2cea77552bcf8f09b56d","bodies":[ |
| {"name":"edge/crlf","body":"# [[Acme]]Titl\n\n- # b\n\n![[fichas:c1]][[Acme#^b1|that]]","blocks":["heading:1","item:bullet_list:0:true","paragraph"]}, |
| {"name":"edge/lone-cr","body":"a\n\n*a\nb*\n\n- cword [[Acme]]\n- ---d~1. ~~|c\n\na","blocks":["paragraph","paragraph","item:bullet_list:0:true","item:bullet_list:0:false","paragraph"]}, |
| {"name":"edge/mixed-line-endings","body":" ^ab\n\n*word","blocks":["paragraph","paragraph"]}, |
| @@ -164,6 +164,9 @@ |
| {"name":"import/columns-nested","body":":::: columns\n\n::: column\nIn.- \n\nword Side.\n\n:::\n\n::: column\nR[[2026-11-12]]ig[ [ ] ] ht.\n\n:::\n\n::::\n\n#","blocks":["columns","column","paragraph","paragraph","column_end","column","paragraph","column_end","columns_end","paragraph"]}, |
| {"name":"import/columns-fence-text","body":":::: columns\n\n::: column\n# :::\n\numns\n\n:::\n\n::: column\n:::: - co\n\n:::\n\n::: column\n:::\n\n::: column\n:::\n\n::::","blocks":["columns","column","paragraph","paragraph","column_end","column","paragraph","column_end","column","column_end","column","column_end","columns_end"]}, |
| {"name":"import/columns-empty","body":":::: columns\n\n::: column\n[ od a\n\n:::\n\n::: column\n![[fichas:c1]]\n\n:::\n\n::::","blocks":["columns","column","paragraph","column_end","column","paragraph","column_end","columns_end"]}, |
| +{"name":"import/columns-widths","body":":::: columns\n\n::: column\nNarrow.\n\n:::\n\n::: column\nWid[ ] \ne[ ] .\n\n[[2026-11-12]]\n\n:::\n\n::::\n\n--","blocks":["columns","column","paragraph","column_end","column","paragraph","paragraph","column_end","columns_end","paragraph"]}, |
| +{"name":"import/columns-even","body":":::: columns\n\n::: column\nHa# lf```.[ ] \n\n:::\n\n::: column\nHalf [[Acme#^b1|that]]too.\n\nHalf [[Acme#^b1|that]]too.\n\n:::\n\n::: column\n]a \n\nHalf [[Acme#^b1|that]]too.\n\nHalf [[Acme#^b1|that]] ^abtoo.\n\n:::\n\n::::","blocks":["columns","column","paragraph","column_end","column","paragraph","paragraph","column_end","column","paragraph","paragraph","paragraph","column_end","columns_end"]}, |
| +{"name":"import/columns-equal-ones","body":":::: columns\n\n::: column\nOn`e.---\n\n:::\n\n::: column\nTwo`.`\n\n:::\n\n::::","blocks":["columns","column","paragraph","column_end","column","paragraph","column_end","columns_end"]}, |
| {"name":"import/tabs","body":".**Firs**\n**t ta```b**\n\n.**Firs**\n**t tab**.**Firs**\n**t tab**\n\n![[fichas:c1]]```![[fichas:c1]]","blocks":["paragraph","paragraph","paragraph"]}, |
| {"name":"import/synced","body":"ced word word text.\n\nrrrroor*ed~~~*.","blocks":["paragraph","paragraph"]}, |
| {"name":"import/synced-unshared","body":"From Notion: a synced block whose or~~~iginal wasn't shared with **th**e import.From Notion: a synced block whose original wasn","blocks":["paragraph"]}, |
diff --git a/internal/mapa/markup/testdata/golden.json b/internal/mapa/markup/testdata/golden.json| index 153c9fc..3b415e7 100644 |
| --- a/internal/mapa/markup/testdata/golden.json |
| +++ b/internal/mapa/markup/testdata/golden.json |
| @@ -164,6 +164,9 @@ |
| {"name":"import/columns-nested","body":":::: columns\n\n::: column\nIn.\n\nSide.\n\n:::\n\n::: column\nRight.\n\n:::\n\n::::","blocks":[{"kind":"columns","level":2,"ordered":false,"marker":"","start":0,"end":12,"source":":::: columns","plain":"","spans":[]},{"kind":"column","level":0,"ordered":false,"marker":"","start":14,"end":24,"source":"::: column","column":1,"plain":"","spans":[]},{"kind":"paragraph","level":0,"ordered":false,"marker":"","start":25,"end":28,"source":"In.","column":1,"plain":"In.","spans":[{"kind":"text","text":"In.","target":"","anchor":"","url":"","source":"In."}]},{"kind":"paragraph","level":0,"ordered":false,"marker":"","start":30,"end":35,"source":"Side.","column":1,"plain":"Side.","spans":[{"kind":"text","text":"Side.","target":"","anchor":"","url":"","source":"Side."}]},{"kind":"column_end","level":0,"ordered":false,"marker":"","start":37,"end":40,"source":":::","column":1,"plain":"","spans":[]},{"kind":"column","level":0,"ordered":false,"marker":"","start":42,"end":52,"source":"::: column","column":2,"plain":"","spans":[]},{"kind":"paragraph","level":0,"ordered":false,"marker":"","start":53,"end":59,"source":"Right.","column":2,"plain":"Right.","spans":[{"kind":"text","text":"Right.","target":"","anchor":"","url":"","source":"Right."}]},{"kind":"column_end","level":0,"ordered":false,"marker":"","start":61,"end":64,"source":":::","column":2,"plain":"","spans":[]},{"kind":"columns_end","level":0,"ordered":false,"marker":"","start":66,"end":70,"source":"::::","plain":"","spans":[]}],"links":[],"images":[],"html":"<div mapa-columns=\"2\"><div mapa-column><p>In.</p><p>Side.</p></div><div mapa-column><p>Right.</p></div></div><p><br class=\"ProseMirror-trailingBreak\"></p>"}, |
| {"name":"import/columns-fence-text","body":":::: columns\n\n::: column\n:::\n\n:::\n\n::: column\n:::: columns\n\n:::\n\n::::","blocks":[{"kind":"columns","level":2,"ordered":false,"marker":"","start":0,"end":12,"source":":::: columns","plain":"","spans":[]},{"kind":"column","level":0,"ordered":false,"marker":"","start":14,"end":24,"source":"::: column","column":1,"plain":"","spans":[]},{"kind":"paragraph","level":0,"ordered":false,"marker":"","start":25,"end":31,"source":":::","column":1,"plain":":::","spans":[{"kind":"text","text":":::","target":"","anchor":"","url":"","source":":::"}]},{"kind":"column_end","level":0,"ordered":false,"marker":"","start":33,"end":36,"source":":::","column":1,"plain":"","spans":[]},{"kind":"column","level":0,"ordered":false,"marker":"","start":38,"end":48,"source":"::: column","column":2,"plain":"","spans":[]},{"kind":"paragraph","level":0,"ordered":false,"marker":"","start":49,"end":64,"source":":::: columns","column":2,"plain":":::: columns","spans":[{"kind":"text","text":":::: columns","target":"","anchor":"","url":"","source":":::: columns"}]},{"kind":"column_end","level":0,"ordered":false,"marker":"","start":66,"end":69,"source":":::","column":2,"plain":"","spans":[]},{"kind":"columns_end","level":0,"ordered":false,"marker":"","start":71,"end":75,"source":"::::","plain":"","spans":[]}],"links":[],"images":[],"html":"<div mapa-columns=\"2\"><div mapa-column><p>:::</p></div><div mapa-column><p>:::: columns</p></div></div><p><br class=\"ProseMirror-trailingBreak\"></p>"}, |
| {"name":"import/columns-empty","body":":::: columns\n\n::: column\n:::\n\n::: column\nB.\n\n:::\n\n::::","blocks":[{"kind":"columns","level":2,"ordered":false,"marker":"","start":0,"end":12,"source":":::: columns","plain":"","spans":[]},{"kind":"column","level":0,"ordered":false,"marker":"","start":14,"end":24,"source":"::: column","column":1,"plain":"","spans":[]},{"kind":"column_end","level":0,"ordered":false,"marker":"","start":25,"end":28,"source":":::","column":1,"plain":"","spans":[]},{"kind":"column","level":0,"ordered":false,"marker":"","start":30,"end":40,"source":"::: column","column":2,"plain":"","spans":[]},{"kind":"paragraph","level":0,"ordered":false,"marker":"","start":41,"end":43,"source":"B.","column":2,"plain":"B.","spans":[{"kind":"text","text":"B.","target":"","anchor":"","url":"","source":"B."}]},{"kind":"column_end","level":0,"ordered":false,"marker":"","start":45,"end":48,"source":":::","column":2,"plain":"","spans":[]},{"kind":"columns_end","level":0,"ordered":false,"marker":"","start":50,"end":54,"source":"::::","plain":"","spans":[]}],"links":[],"images":[],"html":"<div mapa-columns=\"2\"><div mapa-column><p><br class=\"ProseMirror-trailingBreak\"></p></div><div mapa-column><p>B.</p></div></div><p><br class=\"ProseMirror-trailingBreak\"></p>"}, |
| +{"name":"import/columns-widths","body":":::: columns\n\n::: column\nNarrow.\n\n:::\n\n::: column\nWide.\n\n:::\n\n::::","blocks":[{"kind":"columns","level":2,"ordered":false,"marker":"","start":0,"end":12,"source":":::: columns","plain":"","spans":[]},{"kind":"column","level":0,"ordered":false,"marker":"","start":14,"end":24,"source":"::: column","column":1,"plain":"","spans":[]},{"kind":"paragraph","level":0,"ordered":false,"marker":"","start":25,"end":32,"source":"Narrow.","column":1,"plain":"Narrow.","spans":[{"kind":"text","text":"Narrow.","target":"","anchor":"","url":"","source":"Narrow."}]},{"kind":"column_end","level":0,"ordered":false,"marker":"","start":34,"end":37,"source":":::","column":1,"plain":"","spans":[]},{"kind":"column","level":0,"ordered":false,"marker":"","start":39,"end":49,"source":"::: column","column":2,"plain":"","spans":[]},{"kind":"paragraph","level":0,"ordered":false,"marker":"","start":50,"end":55,"source":"Wide.","column":2,"plain":"Wide.","spans":[{"kind":"text","text":"Wide.","target":"","anchor":"","url":"","source":"Wide."}]},{"kind":"column_end","level":0,"ordered":false,"marker":"","start":57,"end":60,"source":":::","column":2,"plain":"","spans":[]},{"kind":"columns_end","level":0,"ordered":false,"marker":"","start":62,"end":66,"source":"::::","plain":"","spans":[]}],"links":[],"images":[],"html":"<div mapa-columns=\"2\"><div mapa-column><p>Narrow.</p></div><div mapa-column><p>Wide.</p></div></div><p><br class=\"ProseMirror-trailingBreak\"></p>"}, |
| +{"name":"import/columns-even","body":":::: columns\n\n::: column\nHalf.\n\n:::\n\n::: column\nHalf too.\n\n:::\n\n::::","blocks":[{"kind":"columns","level":2,"ordered":false,"marker":"","start":0,"end":12,"source":":::: columns","plain":"","spans":[]},{"kind":"column","level":0,"ordered":false,"marker":"","start":14,"end":24,"source":"::: column","column":1,"plain":"","spans":[]},{"kind":"paragraph","level":0,"ordered":false,"marker":"","start":25,"end":30,"source":"Half.","column":1,"plain":"Half.","spans":[{"kind":"text","text":"Half.","target":"","anchor":"","url":"","source":"Half."}]},{"kind":"column_end","level":0,"ordered":false,"marker":"","start":32,"end":35,"source":":::","column":1,"plain":"","spans":[]},{"kind":"column","level":0,"ordered":false,"marker":"","start":37,"end":47,"source":"::: column","column":2,"plain":"","spans":[]},{"kind":"paragraph","level":0,"ordered":false,"marker":"","start":48,"end":57,"source":"Half too.","column":2,"plain":"Half too.","spans":[{"kind":"text","text":"Half too.","target":"","anchor":"","url":"","source":"Half too."}]},{"kind":"column_end","level":0,"ordered":false,"marker":"","start":59,"end":62,"source":":::","column":2,"plain":"","spans":[]},{"kind":"columns_end","level":0,"ordered":false,"marker":"","start":64,"end":68,"source":"::::","plain":"","spans":[]}],"links":[],"images":[],"html":"<div mapa-columns=\"2\"><div mapa-column><p>Half.</p></div><div mapa-column><p>Half too.</p></div></div><p><br class=\"ProseMirror-trailingBreak\"></p>"}, |
| +{"name":"import/columns-equal-ones","body":":::: columns\n\n::: column\nOne.\n\n:::\n\n::: column\nTwo.\n\n:::\n\n::::","blocks":[{"kind":"columns","level":2,"ordered":false,"marker":"","start":0,"end":12,"source":":::: columns","plain":"","spans":[]},{"kind":"column","level":0,"ordered":false,"marker":"","start":14,"end":24,"source":"::: column","column":1,"plain":"","spans":[]},{"kind":"paragraph","level":0,"ordered":false,"marker":"","start":25,"end":29,"source":"One.","column":1,"plain":"One.","spans":[{"kind":"text","text":"One.","target":"","anchor":"","url":"","source":"One."}]},{"kind":"column_end","level":0,"ordered":false,"marker":"","start":31,"end":34,"source":":::","column":1,"plain":"","spans":[]},{"kind":"column","level":0,"ordered":false,"marker":"","start":36,"end":46,"source":"::: column","column":2,"plain":"","spans":[]},{"kind":"paragraph","level":0,"ordered":false,"marker":"","start":47,"end":51,"source":"Two.","column":2,"plain":"Two.","spans":[{"kind":"text","text":"Two.","target":"","anchor":"","url":"","source":"Two."}]},{"kind":"column_end","level":0,"ordered":false,"marker":"","start":53,"end":56,"source":":::","column":2,"plain":"","spans":[]},{"kind":"columns_end","level":0,"ordered":false,"marker":"","start":58,"end":62,"source":"::::","plain":"","spans":[]}],"links":[],"images":[],"html":"<div mapa-columns=\"2\"><div mapa-column><p>One.</p></div><div mapa-column><p>Two.</p></div></div><p><br class=\"ProseMirror-trailingBreak\"></p>"}, |
| {"name":"import/tabs","body":"**First tab**\n\nIn it.","blocks":[{"kind":"paragraph","level":0,"ordered":false,"marker":"","start":0,"end":13,"source":"**First tab**","plain":"**First tab**","spans":[{"kind":"text","text":"**First tab**","target":"","anchor":"","url":"","source":"**First tab**"}]},{"kind":"paragraph","level":0,"ordered":false,"marker":"","start":15,"end":21,"source":"In it.","plain":"In it.","spans":[{"kind":"text","text":"In it.","target":"","anchor":"","url":"","source":"In it."}]}],"links":[],"images":[],"html":"<p><strong>First tab</strong></p><p>In it.</p>"}, |
| {"name":"import/synced","body":"Synced text.\n\nMirrored.","blocks":[{"kind":"paragraph","level":0,"ordered":false,"marker":"","start":0,"end":12,"source":"Synced text.","plain":"Synced text.","spans":[{"kind":"text","text":"Synced text.","target":"","anchor":"","url":"","source":"Synced text."}]},{"kind":"paragraph","level":0,"ordered":false,"marker":"","start":14,"end":23,"source":"Mirrored.","plain":"Mirrored.","spans":[{"kind":"text","text":"Mirrored.","target":"","anchor":"","url":"","source":"Mirrored."}]}],"links":[],"images":[],"html":"<p>Synced text.</p><p>Mirrored.</p>"}, |
| {"name":"import/synced-unshared","body":"> From Notion: a synced block whose original wasn't shared with the import.","blocks":[{"kind":"quote","level":0,"ordered":false,"marker":"","start":0,"end":75,"source":"> From Notion: a synced block whose original wasn't shared with the import.","plain":"From Notion: a synced block whose original wasn't shared with the import.","spans":[{"kind":"text","text":"From Notion: a synced block whose original wasn't shared with the import.","target":"","anchor":"","url":"","source":"From Notion: a synced block whose original wasn't shared with the import."}]}],"links":[],"images":[],"html":"<blockquote><p>From Notion: a synced block whose original wasn't shared with the import.</p></blockquote><p><br class=\"ProseMirror-trailingBreak\"></p>"}, |
diff --git a/internal/mapa/notionmd/blocks.go b/internal/mapa/notionmd/blocks.go| index d2a22d8..6dcb970 100644 |
| --- a/internal/mapa/notionmd/blocks.go |
| +++ b/internal/mapa/notionmd/blocks.go |
| @@ -148,6 +148,9 @@ func (mapper *mapper) columns(block Block, _ int) { |
| } |
| return |
| } |
| + if unevenWidths(block.Children) { |
| + mapper.loss(LossWidths) |
| + } |
| mapper.fence(markup.Columns, ":::: columns") |
| mapper.inColumn = true |
| for _, column := range block.Children { |
| @@ -159,6 +162,31 @@ func (mapper *mapper) columns(block Block, _ int) { |
| mapper.fence(markup.ColumnsEnd, "::::") |
| } |
| +// unevenWidths is columns whose width ratios differ: Mapa's layouts are |
| +// even, so the widths are counted (columns and icons spec §6.2). When |
| +// every column has a ratio they are compared with each other, whatever |
| +// they sum to (Fable on phase 4, L5); a column with none is an even |
| +// share, 1/n, against which the others are compared. |
| +func unevenWidths(columns []Block) bool { |
| + share := columns[0].WidthRatio |
| + for _, column := range columns { |
| + if column.WidthRatio == 0 { |
| + share = 1 / float64(len(columns)) |
| + break |
| + } |
| + } |
| + for _, column := range columns { |
| + ratio := column.WidthRatio |
| + if ratio == 0 { |
| + ratio = 1 / float64(len(columns)) |
| + } |
| + if ratio-share > 0.001*share || share-ratio > 0.001*share { |
| + return true |
| + } |
| + } |
| + return false |
| +} |
| + |
| // fence adds one of a layout's fence lines. |
| func (mapper *mapper) fence(kind, line string) { |
| mapper.out = append(mapper.out, written{kind: kind, literal: line}) |
diff --git a/internal/mapa/notionmd/fixtures_blocks_test.go b/internal/mapa/notionmd/fixtures_blocks_test.go| index ea164cc..12d545b 100644 |
| --- a/internal/mapa/notionmd/fixtures_blocks_test.go |
| +++ b/internal/mapa/notionmd/fixtures_blocks_test.go |
| @@ -81,6 +81,25 @@ func containerFixtures() []fixture { |
| page("columns-empty", with(Block{Type: "column_list", Known: true}, |
| Block{Type: "column", Known: true}, |
| with(Block{Type: "column", Known: true}, para(txt("B."))))), |
| + // Widths that differ are counted; even ones, given or not, are |
| + // not (columns and icons spec §6.2). |
| + page("columns-widths", with(Block{Type: "column_list", Known: true}, |
| + with(Block{Type: "column", Known: true, WidthRatio: 0.25}, |
| + para(txt("Narrow."))), |
| + with(Block{Type: "column", Known: true, WidthRatio: 0.75}, |
| + para(txt("Wide."))))), |
| + page("columns-even", with(Block{Type: "column_list", Known: true}, |
| + with(Block{Type: "column", Known: true, WidthRatio: 0.5}, |
| + para(txt("Half."))), |
| + with(Block{Type: "column", Known: true}, para(txt("Half too."))))), |
| + // Equal ratios that do not sum to 1 are even (Fable on phase 4, |
| + // L5). |
| + page("columns-equal-ones", with(Block{Type: "column_list", |
| + Known: true}, |
| + with(Block{Type: "column", Known: true, WidthRatio: 1}, |
| + para(txt("One."))), |
| + with(Block{Type: "column", Known: true, WidthRatio: 1}, |
| + para(txt("Two."))))), |
| page("tabs", with(blk("tab", txt("First tab")), para(txt("In it.")))), |
| page("synced", with(Block{Type: "synced_block", Known: true}, |
| para(txt("Synced text."))), with(Block{Type: "synced_block", |
| @@ -109,8 +128,11 @@ func containerFixtures() []fixture { |
| live(hexID("a1"), "Acme"), |
| page("database", named(Block{Type: "child_database", Known: true, |
| Title: "Projects"}, "db-1")), |
| + // The look is the runner's: the mapper writes nothing of it |
| + // (columns and icons spec §6.1). |
| {Name: "page-icon-cover", Page: Page{ID: "page-icon", |
| - HasIcon: true, HasCover: true, |
| + Icon: &Look{Type: "emoji", Emoji: "🚀"}, |
| + Cover: &Look{Type: "external", URL: "https://example.com/c.jpg"}, |
| Blocks: []Block{para(txt("A page with an icon and a cover."))}}}, |
| {Name: "parent-and-date", Page: Page{ID: "page-day", |
| Blocks: []Block{para(txt("What happened that day."))}}, |
diff --git a/internal/mapa/notionmd/mapper.go b/internal/mapa/notionmd/mapper.go| index ba9a765..f897832 100644 |
| --- a/internal/mapa/notionmd/mapper.go |
| +++ b/internal/mapa/notionmd/mapper.go |
| @@ -24,12 +24,6 @@ func render(page Page, options Options) (Result, error) { |
| page = normalisePage(page) |
| mapper := &mapper{options: options, |
| result: Result{Losses: map[string]int{}}} |
| - if page.HasIcon { |
| - mapper.loss(LossIcon) |
| - } |
| - if page.HasCover { |
| - mapper.loss(LossCover) |
| - } |
| if options.Parent != "" { |
| mapper.emit(written{kind: markup.Paragraph, lines: []line{{ |
| fixed("In: "), {kind: wiki, target: options.Parent}}}}) |
diff --git a/internal/mapa/notionmd/render.go b/internal/mapa/notionmd/render.go| index 4d1d8bf..5032827 100644 |
| --- a/internal/mapa/notionmd/render.go |
| +++ b/internal/mapa/notionmd/render.go |
| @@ -91,6 +91,7 @@ const ( |
| LossBlock = "block:" // + the Notion type: a block not imported |
| LossToggle = "toggle" |
| LossColumns = "columns" |
| + LossWidths = "column_widths" |
| LossTabs = "tabs" |
| LossSynced = "synced" |
| LossIndent = "indent" |
| @@ -104,8 +105,6 @@ const ( |
| LossMarkStar = "mark_star" |
| LossMarkLink = "mark_link" |
| LossCodeFence = "code_fence" |
| - LossIcon = "icon" |
| - LossCover = "cover" |
| LossFile = "file" |
| LossStartNumber = "start_number" |
| LossBlockAnchor = "block_anchor" |
diff --git a/internal/mapa/notionmd/testdata/fixtures/columns-equal-ones.json b/internal/mapa/notionmd/testdata/fixtures/columns-equal-ones.json| new file mode 100644 |
| index 0000000..a256dd7 |
| --- /dev/null |
| +++ b/internal/mapa/notionmd/testdata/fixtures/columns-equal-ones.json |
| @@ -0,0 +1,54 @@ |
| +{ |
| + "name": "columns-equal-ones", |
| + "page": { |
| + "id": "page-columns-equal-ones", |
| + "seq": 0, |
| + "blocks": [ |
| + { |
| + "id": "", |
| + "type": "column_list", |
| + "known": true, |
| + "children": [ |
| + { |
| + "id": "", |
| + "type": "column", |
| + "known": true, |
| + "width": 1, |
| + "children": [ |
| + { |
| + "id": "", |
| + "type": "paragraph", |
| + "known": true, |
| + "text": [ |
| + { |
| + "type": "text", |
| + "text": "One." |
| + } |
| + ] |
| + } |
| + ] |
| + }, |
| + { |
| + "id": "", |
| + "type": "column", |
| + "known": true, |
| + "width": 1, |
| + "children": [ |
| + { |
| + "id": "", |
| + "type": "paragraph", |
| + "known": true, |
| + "text": [ |
| + { |
| + "type": "text", |
| + "text": "Two." |
| + } |
| + ] |
| + } |
| + ] |
| + } |
| + ] |
| + } |
| + ] |
| + } |
| +} |
diff --git a/internal/mapa/notionmd/testdata/fixtures/columns-even.json b/internal/mapa/notionmd/testdata/fixtures/columns-even.json| new file mode 100644 |
| index 0000000..fe22cf1 |
| --- /dev/null |
| +++ b/internal/mapa/notionmd/testdata/fixtures/columns-even.json |
| @@ -0,0 +1,53 @@ |
| +{ |
| + "name": "columns-even", |
| + "page": { |
| + "id": "page-columns-even", |
| + "seq": 0, |
| + "blocks": [ |
| + { |
| + "id": "", |
| + "type": "column_list", |
| + "known": true, |
| + "children": [ |
| + { |
| + "id": "", |
| + "type": "column", |
| + "known": true, |
| + "width": 0.5, |
| + "children": [ |
| + { |
| + "id": "", |
| + "type": "paragraph", |
| + "known": true, |
| + "text": [ |
| + { |
| + "type": "text", |
| + "text": "Half." |
| + } |
| + ] |
| + } |
| + ] |
| + }, |
| + { |
| + "id": "", |
| + "type": "column", |
| + "known": true, |
| + "children": [ |
| + { |
| + "id": "", |
| + "type": "paragraph", |
| + "known": true, |
| + "text": [ |
| + { |
| + "type": "text", |
| + "text": "Half too." |
| + } |
| + ] |
| + } |
| + ] |
| + } |
| + ] |
| + } |
| + ] |
| + } |
| +} |
diff --git a/internal/mapa/notionmd/testdata/fixtures/columns-widths.json b/internal/mapa/notionmd/testdata/fixtures/columns-widths.json| new file mode 100644 |
| index 0000000..ded32c7 |
| --- /dev/null |
| +++ b/internal/mapa/notionmd/testdata/fixtures/columns-widths.json |
| @@ -0,0 +1,54 @@ |
| +{ |
| + "name": "columns-widths", |
| + "page": { |
| + "id": "page-columns-widths", |
| + "seq": 0, |
| + "blocks": [ |
| + { |
| + "id": "", |
| + "type": "column_list", |
| + "known": true, |
| + "children": [ |
| + { |
| + "id": "", |
| + "type": "column", |
| + "known": true, |
| + "width": 0.25, |
| + "children": [ |
| + { |
| + "id": "", |
| + "type": "paragraph", |
| + "known": true, |
| + "text": [ |
| + { |
| + "type": "text", |
| + "text": "Narrow." |
| + } |
| + ] |
| + } |
| + ] |
| + }, |
| + { |
| + "id": "", |
| + "type": "column", |
| + "known": true, |
| + "width": 0.75, |
| + "children": [ |
| + { |
| + "id": "", |
| + "type": "paragraph", |
| + "known": true, |
| + "text": [ |
| + { |
| + "type": "text", |
| + "text": "Wide." |
| + } |
| + ] |
| + } |
| + ] |
| + } |
| + ] |
| + } |
| + ] |
| + } |
| +} |
diff --git a/internal/mapa/notionmd/testdata/fixtures/page-icon-cover.json b/internal/mapa/notionmd/testdata/fixtures/page-icon-cover.json| index 54d8411..c8a4260 100644 |
| --- a/internal/mapa/notionmd/testdata/fixtures/page-icon-cover.json |
| +++ b/internal/mapa/notionmd/testdata/fixtures/page-icon-cover.json |
| @@ -2,8 +2,14 @@ |
| "name": "page-icon-cover", |
| "page": { |
| "id": "page-icon", |
| - "icon": true, |
| - "cover": true, |
| + "pageIcon": { |
| + "type": "emoji", |
| + "emoji": "🚀" |
| + }, |
| + "pageCover": { |
| + "type": "external", |
| + "url": "https://example.com/c.jpg" |
| + }, |
| "seq": 0, |
| "blocks": [ |
| { |
diff --git a/internal/mapa/notionmd/testdata/golden/columns-equal-ones.json b/internal/mapa/notionmd/testdata/golden/columns-equal-ones.json| new file mode 100644 |
| index 0000000..6337d24 |
| --- /dev/null |
| +++ b/internal/mapa/notionmd/testdata/golden/columns-equal-ones.json |
| @@ -0,0 +1,5 @@ |
| +{ |
| + "result": { |
| + "Body": "" |
| + } |
| +} |
diff --git a/internal/mapa/notionmd/testdata/golden/columns-equal-ones.md b/internal/mapa/notionmd/testdata/golden/columns-equal-ones.md| new file mode 100644 |
| index 0000000..0990daa |
| --- /dev/null |
| +++ b/internal/mapa/notionmd/testdata/golden/columns-equal-ones.md |
| @@ -0,0 +1,13 @@ |
| +:::: columns |
| + |
| +::: column |
| +One. |
| + |
| +::: |
| + |
| +::: column |
| +Two. |
| + |
| +::: |
| + |
| +:::: |
diff --git a/internal/mapa/notionmd/testdata/golden/columns-even.json b/internal/mapa/notionmd/testdata/golden/columns-even.json| new file mode 100644 |
| index 0000000..6337d24 |
| --- /dev/null |
| +++ b/internal/mapa/notionmd/testdata/golden/columns-even.json |
| @@ -0,0 +1,5 @@ |
| +{ |
| + "result": { |
| + "Body": "" |
| + } |
| +} |
diff --git a/internal/mapa/notionmd/testdata/golden/columns-even.md b/internal/mapa/notionmd/testdata/golden/columns-even.md| new file mode 100644 |
| index 0000000..8d8cdbf |
| --- /dev/null |
| +++ b/internal/mapa/notionmd/testdata/golden/columns-even.md |
| @@ -0,0 +1,13 @@ |
| +:::: columns |
| + |
| +::: column |
| +Half. |
| + |
| +::: |
| + |
| +::: column |
| +Half too. |
| + |
| +::: |
| + |
| +:::: |
diff --git a/internal/mapa/notionmd/testdata/golden/columns-widths.json b/internal/mapa/notionmd/testdata/golden/columns-widths.json| new file mode 100644 |
| index 0000000..2a56541 |
| --- /dev/null |
| +++ b/internal/mapa/notionmd/testdata/golden/columns-widths.json |
| @@ -0,0 +1,8 @@ |
| +{ |
| + "result": { |
| + "Body": "", |
| + "losses": { |
| + "column_widths": 1 |
| + } |
| + } |
| +} |
diff --git a/internal/mapa/notionmd/testdata/golden/columns-widths.md b/internal/mapa/notionmd/testdata/golden/columns-widths.md| new file mode 100644 |
| index 0000000..8be89be |
| --- /dev/null |
| +++ b/internal/mapa/notionmd/testdata/golden/columns-widths.md |
| @@ -0,0 +1,13 @@ |
| +:::: columns |
| + |
| +::: column |
| +Narrow. |
| + |
| +::: |
| + |
| +::: column |
| +Wide. |
| + |
| +::: |
| + |
| +:::: |
diff --git a/internal/mapa/notionmd/testdata/golden/page-icon-cover.json b/internal/mapa/notionmd/testdata/golden/page-icon-cover.json| index 66581d1..6337d24 100644 |
| --- a/internal/mapa/notionmd/testdata/golden/page-icon-cover.json |
| +++ b/internal/mapa/notionmd/testdata/golden/page-icon-cover.json |
| @@ -1,9 +1,5 @@ |
| { |
| "result": { |
| - "Body": "", |
| - "losses": { |
| - "cover": 1, |
| - "icon": 1 |
| - } |
| + "Body": "" |
| } |
| } |
diff --git a/internal/mapa/notionmd/tree.go b/internal/mapa/notionmd/tree.go| index 03e030b..131efc5 100644 |
| --- a/internal/mapa/notionmd/tree.go |
| +++ b/internal/mapa/notionmd/tree.go |
| @@ -18,14 +18,25 @@ type Page struct { |
| Parent string `json:"parent,omitempty"` |
| Created string `json:"created,omitempty"` |
| Edited string `json:"edited,omitempty"` |
| - // HasIcon and HasCover are counted and not imported (§9.1). |
| - HasIcon bool `json:"icon,omitempty"` |
| - HasCover bool `json:"cover,omitempty"` |
| + // Icon and Cover are the page's look as Notion gives it (columns and |
| + // icons spec §6.1). The runner imports them before the page's write; |
| + // the mapper writes nothing of them. Their keys are new: a tree |
| + // staged before they were read decodes with none. |
| + Icon *Look `json:"pageIcon,omitempty"` |
| + Cover *Look `json:"pageCover,omitempty"` |
| // Seq is the page's place in survey order (§9.2). |
| Seq int `json:"seq"` |
| Blocks []Block `json:"blocks,omitempty"` |
| } |
| +// Look is a page's icon or cover: Type is Notion's (emoji, |
| +// custom_emoji, file or external), Emoji an emoji icon's, URL the rest's. |
| +type Look struct { |
| + Type string `json:"type"` |
| + Emoji string `json:"emoji,omitempty"` |
| + URL string `json:"url,omitempty"` |
| +} |
| + |
| // Block is one block and its children. |
| type Block struct { |
| ID string `json:"id"` |
| @@ -41,6 +52,9 @@ type Block struct { |
| Checked bool `json:"checked,omitempty"` |
| Toggleable bool `json:"toggleable,omitempty"` |
| Language string `json:"language,omitempty"` |
| + // WidthRatio is a column's share of its column_list, when Notion |
| + // gives one (columns and icons spec §6.2): not imported, counted. |
| + WidthRatio float64 `json:"width,omitempty"` |
| // Color is the block's colour, which the subset cannot say: counted. |
| Color string `json:"color,omitempty"` |
| // Emoji is a callout's icon when it is an emoji; IconType names any |
diff --git a/internal/mapa/templates/import.html b/internal/mapa/templates/import.html| index 2a6e04c..9dad0c6 100644 |
| --- a/internal/mapa/templates/import.html |
| +++ b/internal/mapa/templates/import.html |
| @@ -74,6 +74,10 @@ |
| <dt>Images imported</dt><dd>{{number L .Images.Imported}}</dd> |
| <dt>Images left as links</dt><dd>{{number L .Images.Links}}</dd> |
| <dt>Images not imported</dt><dd>{{range $i, $c := .ImageFailures}}{{if $i}}; {{end}}{{$c.Label}}: {{number L $c.Count}}{{else}}0{{end}}</dd> |
| +<dt>Icons imported</dt><dd>{{number L .Icons}}</dd> |
| +<dt>Icons not imported</dt><dd>{{range $i, $c := .IconFailures}}{{if $i}}; {{end}}{{$c.Label}}: {{number L $c.Count}}{{else}}0{{end}}</dd> |
| +<dt>Banners imported</dt><dd>{{number L .Covers}}</dd> |
| +<dt>Banners not imported</dt><dd>{{range $i, $c := .CoverFailures}}{{if $i}}; {{end}}{{$c.Label}}: {{number L $c.Count}}{{else}}0{{end}}</dd> |
| <dt>Links to pages not shared with the import</dt><dd>{{number L .Unshared}}</dd> |
| <dt>Links still pointing at Notion</dt><dd>{{number L .Notion}}</dd> |
| <dt>Text adjusted so Mapa reads it literally</dt><dd>{{number L .Neutralised}}</dd> |
diff --git a/scripts/mutate/import_looks.go b/scripts/mutate/import_looks.go| new file mode 100644 |
| index 0000000..4e03a2c |
| --- /dev/null |
| +++ b/scripts/mutate/import_looks.go |
| @@ -0,0 +1,55 @@ |
| +package main |
| + |
| +// The columns and icons spec's mutations for the importer's looks |
| +// (§6.1, §6.4, §9): an emoji icon written unchecked, an external cover |
| +// fetched without asking the pin, a look left out of "unchanged", the |
| +// styled revision skipped, an icon's two limits, and a fix-up dropping |
| +// the look it did not prepare. |
| + |
| +const ( |
| + importLooksGo = "internal/mapa/import_looks.go" |
| + importWriteGo = "internal/mapa/import_write.go" |
| + importStoreGo = "internal/mapa/import_store.go" |
| +) |
| + |
| +var importLookMutations = []mutation{ |
| + {gate: "I20", test: "TestI20IconsAreImported", pkg: inside, |
| + name: "an emoji icon written without the list's check", |
| + edits: []edit{{file: importLooksGo, |
| + from: "\t\tmade, err := EmojiIcon(icon.Emoji)", |
| + to: "\t\tmade, err := &Icon{Emoji: icon.Emoji}, error(nil)"}}}, |
| + {gate: "I21", test: "TestI21CoversAreImportedFromThePinOnly", pkg: inside, |
| + name: "an external cover fetched without asking the pin", |
| + edits: []edit{{file: importLooksGo, |
| + from: "(cover.Type == notion.FileExternal && " + |
| + "job.files.Gallery(cover.URL))", |
| + to: "cover.Type == notion.FileExternal"}}}, |
| + {gate: "I24", test: "TestI24ALookChangedInNotionIsStyled", pkg: inside, |
| + name: "unchanged decided without the look", |
| + edits: []edit{{file: importWriteGo, |
| + from: "\t\tentry.current.Body == cleanBody(body) &&\n" + |
| + "\t\tsameLook(entry.current, entry.lookRecord()) {", |
| + to: "\t\tentry.current.Body == cleanBody(body) {"}}}, |
| + {gate: "I24", test: "TestI24RenamedStyledEditedInOrder", pkg: inside, |
| + name: "ImportUpdate writes no styled revision", |
| + edits: []edit{{file: importStoreGo, |
| + from: "\t\tif err := tx.importStyle(&page, &record, actor, " + |
| + "write); err != nil {", |
| + to: "\t\tif err := error(nil); err != nil {"}}}, |
| + {gate: "I20", test: "TestI20IconsAreImported", pkg: inside, |
| + name: "an icon over 512 pixels a side kept", |
| + edits: []edit{{file: importLooksGo, |
| + from: "if pseudo == iconPlace && added.Side() > MaxIconSide {", |
| + to: "if pseudo == iconPlace && added.Side() > 1<<20 {"}}}, |
| + {gate: "I20", test: "TestI20IconsAreImported", pkg: inside, |
| + name: "an icon fetched with the 10 MB cap", |
| + edits: []edit{{file: importLooksGo, |
| + from: "\t\treturn page.Icon.URL, MaxIconBytes", |
| + to: "\t\treturn page.Icon.URL, imageCap"}}}, |
| + {gate: "I24", test: "TestI24AFixUpAfterAResumeKeepsTheIcon", pkg: inside, |
| + name: "a fix-up with no prepared look writes none", |
| + edits: []edit{{file: importWriteGo, |
| + from: "\t\treturn Record{Icon: entry.current.Icon, " + |
| + "Banner: entry.current.Banner}", |
| + to: "\t\treturn Record{}"}}}, |
| +} |
diff --git a/scripts/mutate/main.go b/scripts/mutate/main.go| index bedbf99..d4480da 100644 |
| --- a/scripts/mutate/main.go |
| +++ b/scripts/mutate/main.go |
| @@ -47,6 +47,7 @@ func every() []mutation { |
| all = append(all, columnMutations...) |
| all = append(all, mapperMutations...) |
| all = append(all, importMutations...) |
| + all = append(all, importLookMutations...) |
| return append(all, menuMutations...) |
| } |