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
fix(import): carry Notion bookmark preview image into the link-embed
Elian Dorancbde8d5be6aa
diff --git a/packages/trilium-core/src/services/import/notion/converter.spec.ts b/packages/trilium-core/src/services/import/notion/converter.spec.tsindex 5f44552538..36826cf7ed 100644--- a/packages/trilium-core/src/services/import/notion/converter.spec.ts+++ b/packages/trilium-core/src/services/import/notion/converter.spec.ts@@ -160,10 +160,10 @@ describe("convertNotionHtml — math", () => {});describe("convertNotionHtml — bookmarks", () => {- it("converts a Notion bookmark card to a Trilium link-embed, keeping the favicon", () => {- const input = `<div style="display:contents" dir="ltr"><figure id="386c5eca"><a href="https://triliumnotes.org/" class="bookmark source"><div class="bookmark-info"><div class="bookmark-text"><div class="bookmark-title">Trilium Notes</div><div class="bookmark-description">Trilium is an open-source solution for note-taking and personal knowledge bases. Use it locally or sync with your own server to access notes anywhere.</div></div><div class="bookmark-href"><img src="https://triliumnotes.org/assets/favicon-BI5VJBD3.ico" class="icon bookmark-icon"/>https://triliumnotes.org/</div></div></a></figure></div>`;+ it("converts a Notion bookmark card to a Trilium link-embed, keeping the favicon and preview image", () => {+ const input = `<div style="display:contents" dir="ltr"><figure id="386c5eca"><a href="https://triliumnotes.org/" class="bookmark source"><div class="bookmark-info"><div class="bookmark-text"><div class="bookmark-title">Trilium Notes</div><div class="bookmark-description">Trilium is an open-source solution for note-taking and personal knowledge bases. Use it locally or sync with your own server to access notes anywhere.</div></div><div class="bookmark-href"><img src="https://triliumnotes.org/assets/favicon-BI5VJBD3.ico" class="icon bookmark-icon"/>https://triliumnotes.org/</div></div><img src="https://triliumnotes.org/assets/preview.jpg" class="bookmark-image"/></a></figure></div>`;expect(convertNotionHtml(input)).toBe(- `<section class="link-embed" data-url="https://triliumnotes.org/" data-embed-type="opengraph" data-title="Trilium Notes" data-description="Trilium is an open-source solution for note-taking and personal knowledge bases. Use it locally or sync with your own server to access notes anywhere." data-favicon="https://triliumnotes.org/assets/favicon-BI5VJBD3.ico"></section>`+ `<section class="link-embed" data-url="https://triliumnotes.org/" data-embed-type="opengraph" data-title="Trilium Notes" data-description="Trilium is an open-source solution for note-taking and personal knowledge bases. Use it locally or sync with your own server to access notes anywhere." data-favicon="https://triliumnotes.org/assets/favicon-BI5VJBD3.ico" data-image="https://triliumnotes.org/assets/preview.jpg"></section>`);});diff --git a/packages/trilium-core/src/services/import/notion/converter.ts b/packages/trilium-core/src/services/import/notion/converter.tsindex 933563a8c6..09733543c5 100644--- a/packages/trilium-core/src/services/import/notion/converter.ts+++ b/packages/trilium-core/src/services/import/notion/converter.ts@@ -379,7 +379,8 @@ function convertBookmarks(root: HTMLElement) {const optional: Record<string, string | undefined> = {"data-title": figure.querySelector(".bookmark-title")?.textContent?.trim(),"data-description": figure.querySelector(".bookmark-description")?.textContent?.trim(),- "data-favicon": figure.querySelector("img.bookmark-icon")?.getAttribute("src")+ "data-favicon": figure.querySelector("img.bookmark-icon")?.getAttribute("src"),+ "data-image": figure.querySelector("img.bookmark-image")?.getAttribute("src")};for (const [key, value] of Object.entries(optional)) {if (value) {