From 01b85c55e8a1030b7c0c788f2fd0dbc5da9dc426 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mickae=CC=88l=20Menu?= Date: Sun, 14 Mar 2021 17:20:01 +0100 Subject: [PATCH] Fix looking for mentions of a note with a title containing double quotes --- adapter/sqlite/note_dao.go | 11 ++++++++--- docs/note-frontmatter.md | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/adapter/sqlite/note_dao.go b/adapter/sqlite/note_dao.go index 4e2d866..acb83f6 100644 --- a/adapter/sqlite/note_dao.go +++ b/adapter/sqlite/note_dao.go @@ -407,6 +407,11 @@ func (d *NoteDAO) expandMentionsIntoMatch(opts note.FinderOpts) (note.FinderOpts defer rows.Close() titles := []string{} + + appendTitle := func(t string) { + titles = append(titles, `"`+strings.ReplaceAll(t, `"`, "")+`"`) + } + for rows.Next() { var title, metadataJSON string err := rows.Scan(&title, &metadataJSON) @@ -414,7 +419,7 @@ func (d *NoteDAO) expandMentionsIntoMatch(opts note.FinderOpts) (note.FinderOpts return opts, err } - titles = append(titles, `"`+title+`"`) + appendTitle(title) // Support `aliases` key in the YAML frontmatter, like Obsidian: // https://publish.obsidian.md/help/How+to/Add+aliases+to+note @@ -426,10 +431,10 @@ func (d *NoteDAO) expandMentionsIntoMatch(opts note.FinderOpts) (note.FinderOpts switch aliases := aliases.(type) { case []interface{}: for _, alias := range aliases { - titles = append(titles, `"`+fmt.Sprint(alias)+`"`) + appendTitle(fmt.Sprint(alias)) } case string: - titles = append(titles, `"`+aliases+`"`) + appendTitle(aliases) } } } diff --git a/docs/note-frontmatter.md b/docs/note-frontmatter.md index 5e295f0..2d5abcd 100644 --- a/docs/note-frontmatter.md +++ b/docs/note-frontmatter.md @@ -18,5 +18,6 @@ keywords: [writing, essay, practice] | `date` | Creation date – takes precedence over the file date | | `tags` | List of tags attached to this note | | `keywords` | Alias for `tags` | +| `aliases` | Alternative titles for this note, used by `--mention` | All metadata are indexed and can be printed in `zk list` output, using the template variable `{{metadata.}}`, e.g. `{{metadata.description}}`. The keys are normalized to lower case.