Skip to content

Commit eb4157d

Browse files
committed
fix: added default value for note_path_func
1 parent b6329da commit eb4157d

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

lua/obsidian/config/default.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ return {
2222
workspaces = {},
2323
log_level = vim.log.levels.INFO,
2424
note_id_func = require("obsidian.builtin").zettel_id,
25+
note_path_func = function(spec)
26+
local path = spec.dir / tostring(spec.id)
27+
return path
28+
end,
2529
wiki_link_func = require("obsidian.builtin").wiki_link_id_prefix,
2630
markdown_link_func = require("obsidian.builtin").markdown_link,
2731
preferred_link_style = "wiki",

lua/obsidian/note.lua

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,24 +122,19 @@ end
122122
--- This respects the user's `note_path_func` if configured, otherwise essentially falls back to
123123
--- `note_opts.dir / (note_opts.id .. ".md")`.
124124
---
125-
--- @param id string The note ID
126-
--- @param dir obsidian.Path The note path
125+
---@param id string The note ID
126+
---@param dir obsidian.Path The note path
127127
---@return obsidian.Path
128128
---@private
129129
Note._generate_path = function(id, dir)
130130
---@type obsidian.Path
131131
local path
132132

133-
if Obsidian.opts.note_path_func ~= nil then
134-
path = Path.new(Obsidian.opts.note_path_func { id = id, dir = dir, title = nil })
135-
-- Ensure path is either absolute or inside `opts.dir`.
136-
-- NOTE: `opts.dir` should always be absolute, but for extra safety we handle the case where
137-
-- it's not.
138-
if not path:is_absolute() and (dir:is_absolute() or not dir:is_parent_of(path)) then
139-
path = dir / path
140-
end
141-
else
142-
path = dir / tostring(id)
133+
path = Path.new(Obsidian.opts.note_path_func { id = id, dir = dir })
134+
135+
-- NOTE: `opts.dir` should always be absolute, but for extra safety we handle the case where
136+
if not path:is_absolute() and (dir:is_absolute() or not dir:is_parent_of(path)) then
137+
path = dir / path
143138
end
144139

145140
-- Ensure there is only one ".md" suffix. This might arise if `note_path_func`

lua/obsidian/types.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@
7171
---@field notes_subdir string|?
7272
---@field templates obsidian.config.TemplateOpts
7373
---@field new_notes_location obsidian.config.NewNotesLocation
74-
---@field note_id_func (fun(title: string|?, path: obsidian.Path|?): string)|?
75-
---@field note_path_func (fun(spec: { id: string, dir: obsidian.Path, title: string|? }): string|obsidian.Path)|?
74+
---@field note_id_func (fun(id: string|?, path: obsidian.Path|?): string)|?
75+
---@field note_path_func (fun(spec: { id: string, dir: obsidian.Path }): string|obsidian.Path)|?
7676
---@field wiki_link_func (fun(opts: {path: string, label: string, id: string|?}): string)
7777
---@field markdown_link_func (fun(opts: {path: string, label: string, id: string|?}): string)
7878
---@field preferred_link_style obsidian.config.LinkStyle

0 commit comments

Comments
 (0)