Resolve links relative to notebook dir#646
Conversation
d8295ba to
f37cdc1
Compare
When running commands like such as the following:
zk list --notebook-dir=/path/to/notebook --linked-by inbox/note.md
The path is resolved relative to the current working directory.
If the current working directory is not the notebook directory of a
child of it, resolve the link relative to the notebook root.
f37cdc1 to
eb5ec54
Compare
|
Sorry, had a lot to catch up on here and overlooked that you requested a review! Will look tomorrow. Thanks, as always for the efforts here 🙏 |
|
@WhyNotHugo I'm getting a relative path to the cwd with a build from dev and your pr.
But on the note of relative paths to cwd instead of notebook dir. Is this in fact a bug? I myself would expect that the paths should be returned relative to the cwd if I was executing the command outside the notebook. Arguably its a bit redundant as there is the |
|
I think paths should be relative to cwd only if they point to a path inside the notebook. Otherwise, they should be relative to the notebook root. A relative path that points outside the notebook makes no sense, but it's very convenient to use relative-to-notebook-root from any location. |
|
But by definition, paths will always point to a path inside a notebook as zk is only ever indexing notes inside a notebook?... I don't understand how any command would return paths outside of a notebook. Are you perhaps meaning that paths should only be relative to cwd, if the user is executing the command inside a notebook. While if they execute a command outside the notebook, then the paths should be relative to the notebook root? |
|
Almost, but with one distinction:
If cwd is outside the notebook path, but resolving it relative to cwd points to a path inside the notebook, then the path is resolved relative to cwd.
|
|
So my approach is:
- resolve relative to cwd
- does it point inside notebook? Use that
- else: resolve relative to notebook
|
|
@WhyNotHugo Coming back to this again hit some other problem? Tried both with HEAD and this PR. Seem's like I can't point to a note that isn't at the root of the notebook. Here pointing to a file at the root of the notebook. I remember that there was some work being done on the hrefs logic (that was a suboptimal, because the function just returned the first instance of a filename match, even if that file existed in a different directory, mentioned here #684 (comment)). Not sure if something got merged related to this? |
Reproduces the bug where running the following outside the notebook causes the path to be resolved against the current working directory instead of the notebook directory: