Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix updating links after creating a new note #237

Merged
merged 2 commits into from
Jul 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ All notable changes to this project will be documented in this file.

* [#233](https://github.com/mickael-menu/zk/issues/233) Hide index progress in non-interactive shells.
* [#235](https://github.com/mickael-menu/zk/issues/235) Fix LSP link recognition with unicode (contributed by [@zkbpkp](https://github.com/mickael-menu/zk/issues/235)).
* [#236](https://github.com/mickael-menu/zk/issues/236) Fix updating links after creating a new note.
* [#239](https://github.com/mickael-menu/zk/discussions/239) Support standard input via shell redirection with `zk new`.


## 0.10.1

### Changed
Expand Down
5 changes: 4 additions & 1 deletion internal/adapter/sqlite/note_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ func (ni *NoteIndex) linkMatchesPath(link core.ResolvedLink, path string) (bool,
}

matches := func(href string, allowPartialHref bool) bool {
if href == "" {
return false
}
href = regexp.QuoteMeta(href)

if allowPartialHref {
Expand All @@ -193,7 +196,7 @@ func (ni *NoteIndex) linkMatchesPath(link core.ResolvedLink, path string) (bool,
return matchString("^(?:"+href+"[^/]*|"+href+"/.+)$", path)
}

baseDir := filepath.Dir(link.SourcePath)
baseDir := filepath.Join(ni.notebookPath, filepath.Dir(link.SourcePath))
if relHref, err := ni.relNotebookPath(baseDir, href); err != nil {
if matches(relHref, false) {
return true, nil
Expand Down
Empty file.
9 changes: 9 additions & 0 deletions tests/fixtures/issue-236/2022-07-06.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
title: test note 1
date: 2022-07-06
tags: [tag1]
---

[test note 2](ud1o)
[test note 3](8r8q)

7 changes: 7 additions & 0 deletions tests/fixtures/issue-236/8r8q.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
title: test note 3
date: 2022-07-06
tags: [tag1]
---


8 changes: 8 additions & 0 deletions tests/fixtures/issue-236/ud1o.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: test note 2
date: 2022-07-06
tags: [tag1, tag2]
---

[test note 3](8r8q)

13 changes: 13 additions & 0 deletions tests/issue-236.tesh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Links broken after adding a new note
# https://github.com/mickael-menu/zk/issues/236
$ cd issue-236

$ zk list -qfpath --link-to 8r8q
>2022-07-06.md
>ud1o.md

$ zk new --print-path > /dev/null

$ zk list -qfpath --link-to 8r8q
>2022-07-06.md
>ud1o.md