Add zettel opening by base name matching
This commit is contained in:
parent
325be3c500
commit
e2a97570e0
2 changed files with 23 additions and 4 deletions
|
@ -76,10 +76,12 @@ function ls.get_zettel_by_anchor(anchor, all)
|
|||
end
|
||||
|
||||
function ls.get_zettel_by_ref(ref, files)
|
||||
local name_only_match
|
||||
for full_path, bname in pairs(files) do
|
||||
if bname == ref then return full_path end
|
||||
if full_path == ref then return full_path end
|
||||
if bname == ref then name_only_match = full_path end
|
||||
end
|
||||
return ""
|
||||
return name_only_match
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -171,12 +171,29 @@ describe("get_zettel_by_anchor", function()
|
|||
end)
|
||||
|
||||
describe("get_zettel_by_ref", function()
|
||||
it("should match a full file path for non-zettel files", function()
|
||||
|
||||
it("should return a full file path for file path linked", function()
|
||||
local file_list = {
|
||||
["link/to/my/file.md"] = "file.md",
|
||||
["link/to/my/target-file.md"] = "target-file.md",
|
||||
}
|
||||
assert.same("link/to/my/target-file.md", ls.get_zettel_by_ref("link/to/my/target-file.md", file_list))
|
||||
end)
|
||||
|
||||
it("should return path to matching base name if only that is linked", function()
|
||||
local file_list = {
|
||||
["link/to/my/file.md"] = "file.md",
|
||||
["link/to/my/target-file.md"] = "target-file.md",
|
||||
}
|
||||
assert.same("link/to/my/target-file.md", ls.get_zettel_by_ref("target-file.md", file_list))
|
||||
|
||||
end)
|
||||
|
||||
it("should not return anything if no match exists", function()
|
||||
local file_list = {
|
||||
["link/to/my/file.md"] = "file.md",
|
||||
["link/to/my/no-target-file.md"] = "no-target-file.md",
|
||||
}
|
||||
assert.same(nil, ls.get_zettel_by_ref("target-file.md", file_list))
|
||||
end)
|
||||
|
||||
end)
|
||||
|
|
Loading…
Reference in a new issue