Skip to content

Commit 0506f7d

Browse files
committed
Properly identify links to headers when counting unlinked notes (fixes #3)
1 parent 5a21d2e commit 0506f7d

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Diff for: libgrizzly.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,17 @@ func GetUnlinked(db *gorm.DB, unlinked *[]string) {
207207
GetAllNotes(db, &allNotes)
208208
reference := make(map[string][]string)
209209
r, _ := regexp.Compile("\\(bear:\\/\\/x-callback-url\\/open-note?(.*)\\)")
210+
idr, _ := regexp.Compile("bear:\\/\\/x-callback-url\\/open-note\\?id=([^&)]*)?")
210211
for _, note := range allNotes {
211212
reference[note.Identifier] = make([]string, 0)
212213
matches := r.FindAllString(note.Text, -1)
213214
for _, mark := range matches {
214-
identifier := mark[36 : len(mark)-1]
215-
reference[identifier] = append(reference[identifier], note.Identifier)
215+
216+
idMatches := idr.FindStringSubmatch(mark)
217+
if len(idMatches) >= 2 {
218+
reference[idMatches[1]] = append(reference[idMatches[1]], note.Identifier)
219+
}
220+
216221
}
217222
}
218223
// filter out entries with no backlinks

0 commit comments

Comments
 (0)