Skip to content

Commit

Permalink
Support link aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
colebemis committed Dec 30, 2024
1 parent bba2271 commit f75b6fb
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/components/note-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
8 changes: 7 additions & 1 deletion src/global-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
})
Expand Down
2 changes: 2 additions & 0 deletions src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
1 change: 1 addition & 0 deletions src/utils/parse-note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit f75b6fb

Please sign in to comment.