Skip to content

Build your personal knowledge base with Trilium Notes

client/search: make link previews searchable

Adorian Doran4da14727fbc5
diff --git a/packages/trilium-core/src/services/search/expressions/note_content_fulltext_preprocessor.spec.ts b/packages/trilium-core/src/services/search/expressions/note_content_fulltext_preprocessor.spec.ts
index 0704a8102d..e0390e861b 100644
--- a/packages/trilium-core/src/services/search/expressions/note_content_fulltext_preprocessor.spec.ts
+++ b/packages/trilium-core/src/services/search/expressions/note_content_fulltext_preprocessor.spec.ts
@@ -39,6 +39,20 @@ describe("Canvas preprocessing", () => {
});
});
+describe("Text (HTML) preprocessing", () => {
+ const type: NoteType = "text";
+ const mime = "text/html";
+
+ it("surfaces link-preview title, url and description from data attributes", () => {
+ const content = `<section class="link-embed" data-url="https://en.wikipedia.org/wiki/The_Terminator" data-title="The Terminator - Wikipedia" data-description="A 1984 science fiction film.">&nbsp;</section>`;
+ const result = preprocessContent(content, type, mime);
+
+ expect(result).toContain("the terminator - wikipedia");
+ expect(result).toContain("https://en.wikipedia.org/wiki/the_terminator");
+ expect(result).toContain("a 1984 science fiction film.");
+ });
+});
+
describe("LLM chat preprocessing", () => {
const type: NoteType = "llmChat";
const mime = "application/json";
diff --git a/packages/trilium-core/src/services/search/expressions/note_content_fulltext_preprocessor.ts b/packages/trilium-core/src/services/search/expressions/note_content_fulltext_preprocessor.ts
index 9224e8a74d..252286e97b 100644
--- a/packages/trilium-core/src/services/search/expressions/note_content_fulltext_preprocessor.ts
+++ b/packages/trilium-core/src/services/search/expressions/note_content_fulltext_preprocessor.ts
@@ -9,8 +9,12 @@ export default function preprocessContent(rawContent: string | Uint8Array, type:
if (type === "text" && mime === "text/html") {
if (!raw) {
+ // surface link-preview metadata (title/url/description) as text, since it lives in
+ // data attributes that stripTags would otherwise discard along with the element
+ const previewText = [...content.matchAll(/\sdata-(?:title|url|description)="([^"]*)"/gi)].map((match) => match[1]).join(" ");
+
// Content size already filtered at DB level, safe to process
- content = stripTags(content);
+ content = stripTags(`${previewText} ${content}`);
}
content = content.replace(/&nbsp;/g, " ");