Skip to content

Commit

Permalink
Always ensure note dir exists from Client:create_note
Browse files Browse the repository at this point in the history
See #600
  • Loading branch information
epwalsh committed May 31, 2024
1 parent d808307 commit 49cfe4d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed using templates with frontmatter when `disable_frontmatter` is set to true. Previously the frontmatter would be removed when the template was inserted, now it will be kept unchanged.
- Add compatibility for NVIM 0.11
- Fixed handling check boxes with characters that have a special meaning in regular expressions (e.g. "?").
- `Client:create_note()` will always ensure the parent directory exists, even when not writing the note itself to disk, to avoid downstream issues (see #600).

## [v3.7.12](https://github.com/epwalsh/obsidian.nvim/releases/tag/v3.7.12) - 2024-05-02

Expand Down
8 changes: 7 additions & 1 deletion lua/obsidian/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1727,7 +1727,8 @@ end
--- - `title`: A title to assign the note.
--- - `id`: An ID to assign the note. If not specified one will be generated.
--- - `dir`: An optional directory to place the note in. Relative paths will be interpreted
--- relative to the workspace / vault root.
--- relative to the workspace / vault root. If the directory doesn't exist it will be created,
--- regardless of the value of the `no_write` option.
--- - `aliases`: Additional aliases to assign to the note.
--- - `tags`: Additional tags to assign to the note.
--- - `no_write`: Don't write the note to disk.
Expand All @@ -1753,6 +1754,11 @@ Client.create_note = function(self, opts)
note.title = new_title
end

-- Ensure the parent directory exists.
local parent = path:parent()
assert(parent)
parent:mkdir { parents = true, exist_ok = true }

-- Write to disk.
if not opts.no_write then
note = self:write_note(note, { template = opts.template })
Expand Down

0 comments on commit 49cfe4d

Please sign in to comment.