From f75b6fb08490e237842ae45b3bed2d0bd37363bb Mon Sep 17 00:00:00 2001 From: Cole Bemis Date: Mon, 30 Dec 2024 13:32:23 -0800 Subject: [PATCH] Support link aliases --- src/components/note-editor.tsx | 4 +++- src/global-state.ts | 8 +++++++- src/schema.ts | 2 ++ src/utils/parse-note.ts | 1 + 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/components/note-editor.tsx b/src/components/note-editor.tsx index 0fce7679..22f151fc 100644 --- a/src/components/note-editor.tsx +++ b/src/components/note-editor.tsx @@ -378,8 +378,10 @@ function useNoteCompletion() { return { label: note.displayName, apply: (view, completion, from, to) => { + console.log(note) // Insert link to note - const text = `[[${note.id}|${note.displayName}]]` + const linkText = note.linkAlias || note.displayName + const text = `[[${note.id}|${linkText}]]` const hasClosingBrackets = view.state.sliceDoc(to, to + 2) === "]]" view.dispatch({ diff --git a/src/global-state.ts b/src/global-state.ts index 445ea721..71f5d13e 100644 --- a/src/global-state.ts +++ b/src/global-state.ts @@ -615,7 +615,13 @@ export const sortedNotesAtom = atom((get) => { export const noteSearcherAtom = atom((get) => { const sortedNotes = get(sortedNotesAtom) return new Searcher(sortedNotes, { - keySelector: (note) => [note.title, note.content, note.id], + keySelector: (note) => [ + note.title, + note.displayName, + note.content, + note.id, + note.linkAlias || "", + ], threshold: 0.8, }) }) diff --git a/src/schema.ts b/src/schema.ts index c6952334..99e6dd57 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -27,6 +27,8 @@ export type Note = { title: string /** If the title contains a link (e.g. `# [title](url)`), we use that as the url */ url: string | null + /** The alias to use when linking to this note, from _link_alias frontmatter */ + linkAlias: string | null /** If the note is pinned */ pinned: boolean /** The ids of all notes that are linked to from this note */ diff --git a/src/utils/parse-note.ts b/src/utils/parse-note.ts index 4b86cd8a..b2bf4522 100644 --- a/src/utils/parse-note.ts +++ b/src/utils/parse-note.ts @@ -205,6 +205,7 @@ export const parseNote = memoize((id: NoteId, content: string): Note => { frontmatter, title, url, + linkAlias: typeof frontmatter._link_alias === "string" ? frontmatter._link_alias : null, pinned: frontmatter.pinned === true, dates: Array.from(dates), links: Array.from(links),