Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(import/notion): import checkbox columns as boolean labels
Elian Doran93eb867b4e93
diff --git a/packages/trilium-core/src/services/import/notion/importer.integration.spec.ts b/packages/trilium-core/src/services/import/notion/importer.integration.spec.tsindex df07994606..e61aafec14 100644--- a/packages/trilium-core/src/services/import/notion/importer.integration.spec.ts+++ b/packages/trilium-core/src/services/import/notion/importer.integration.spec.ts@@ -565,6 +565,29 @@ describe("Notion importer — integration", () => {expect(definitions.map((attr) => attr.position)).toEqual([10, 20, 30]);});+ it("imports a checkbox column as a boolean label", async () => {+ const dbId = "388c5eca1b8b8078a20fd18330d81306";+ const onId = "388c5eca1b8b80929a78da7c68154bd7";+ const offId = "388c5eca1b8b80e5903ef480b0523eb1";+ // Notion renders a checkbox as <div class="checkbox checkbox-on|off">.+ const checkbox = (state: string) => `<table class="properties"><tbody><tr class="property-row property-row-checkbox"><th><span class="icon property-icon"><img src="x.svg"/></span>Checkbox</th><td><div class="checkbox checkbox-${state}"></div></td></tr></tbody></table>`;+ const importRoot = await importNotion({+ "DB 388c5eca1b8b8078a20fd18330d81306.html":+ `<html><head><title>DB</title></head><body><div id="${dbId}"><div class="page-body"></div></div></body></html>`,+ "DB/On 388c5eca1b8b80929a78da7c68154bd7.html":+ `<html><head><title>On</title></head><body><div id="${onId}">${checkbox("on")}<div class="page-body"><p>x</p></div></div></body></html>`,+ "DB/Off 388c5eca1b8b80e5903ef480b0523eb1.html":+ `<html><head><title>Off</title></head><body><div id="${offId}">${checkbox("off")}<div class="page-body"><p>y</p></div></div></body></html>`+ });++ const db = importRoot.getChildNotes().find((n) => n.title === "DB");+ expect(db?.getOwnedLabel("label:Checkbox")?.value).toBe("promoted,single,boolean,alias=Checkbox");+ const on = db?.getChildNotes().find((n) => n.title === "On");+ const off = db?.getChildNotes().find((n) => n.title === "Off");+ expect(on?.getOwnedLabelValue("Checkbox")).toBe("true");+ expect(off?.getOwnedLabelValue("Checkbox")).toBe("false");+ });+it("neutralizes commas in a column name so the alias can't corrupt the definition", async () => {const dbId = "388c5eca1b8b8078a20fd18330d81306";const rowId = "388c5eca1b8b80929a78da7c68154bd7";diff --git a/packages/trilium-core/src/services/import/notion/importer.ts b/packages/trilium-core/src/services/import/notion/importer.tsindex e415751dff..685d4d8296 100644--- a/packages/trilium-core/src/services/import/notion/importer.ts+++ b/packages/trilium-core/src/services/import/notion/importer.ts@@ -569,7 +569,8 @@ export function firstChildNotionId(body: HTMLElement | null): string | undefined* - `text` / `select` / `status`: the cell's text → one single-valued property;* - `multi_select`: each `<span class="selected-value">` option → one entry of a multi-valued property;* - `url` / `email` / `phone_number`: the anchor's href → one single-valued url-typed property (email gets `mailto:`, phone `tel:`);- * - `date`: the `<time>` value → a `date`/`datetime` label; a range adds a separate `<name> end` column.+ * - `date`: the `<time>` value → a `date`/`datetime` label; a range adds a separate `<name> end` column;+ * - `checkbox`: `checkbox-on`/`checkbox-off` → a `true`/`false` boolean label.* The importer turns each `{ name, value }` into a Trilium label; blank names/values are skipped (Notion* sometimes emits an empty cell, e.g. an unset multi-select, which should contribute no label). Other types* (dates handled separately by extractDate) fall through untouched.@@ -607,6 +608,12 @@ function extractProperties(root: HTMLElement): NotionProperty[] {}} else if (type === "date") {properties.push(...parseDateProperties(name, cell));+ } else if (type === "checkbox") {+ const checkbox = cell.querySelector("div.checkbox");+ if (checkbox) {+ const value = checkbox.classList.contains("checkbox-on") ? "true" : "false";+ properties.push({ name, value, labelType: "boolean", multiplicity: "single" });+ }}}return properties;