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

Added the functionality from RollOver Daily Todos plugin #559

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Don't use last visual selection when in normal mode with `:ObsidianTags`.
- Fixed a normalization issue with windows paths.

### Added

- Added new pass_over_todos option to allow for passing any incomplete todos from yesterday to today's DailyNote

## [v3.7.10](https://github.com/epwalsh/obsidian.nvim/releases/tag/v3.7.10) - 2024-04-19

### Fixed
Expand Down
24 changes: 21 additions & 3 deletions lua/obsidian/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1973,18 +1973,36 @@ Client._daily = function(self, datetime, opts)
if path:exists() then
note = Note.from_file(path, opts.load)
else
local update_content
note = Note.new(id, {}, self.opts.daily_notes.default_tags or {}, path)

if alias then
note:add_alias(alias)
note.title = alias
end

if not opts.no_write then
self:write_note(note, { template = self.opts.daily_notes.template })
if self.opts.daily_notes.pass_on_todos then
--@type obsidian.Note
--NOTE: potentially use Client.yesterday() with added props?
local yesterday_note = self:daily(-1, { no_write = true }):read_note()
local todo_lines = {}
local TODO_PATTERN = "^%s*-%s%[%s%]%s.*"
if yesterday_note then
for _, line in ipairs(yesterday_note) do
if line:match(TODO_PATTERN) then
table.insert(todo_lines, line)
end
end
update_content = function(contents)
-- this is an in-place operation
vim.list_extend(contents, todo_lines)
return contents
end
end
end
self:write_note(note, { template = self.opts.daily_notes.template, update_content = update_content })
end
end

return note
end

Expand Down
1 change: 1 addition & 0 deletions lua/obsidian/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ end
---@field date_format string|?
---@field alias_format string|?
---@field template string|?
---@field pass_on_todos boolean|?
---@field default_tags string[]|?
config.DailyNotesOpts = {}

Expand Down
18 changes: 18 additions & 0 deletions lua/obsidian/note.lua
Original file line number Diff line number Diff line change
Expand Up @@ -820,4 +820,22 @@ Note.resolve_block = function(self, block_id)
return n:resolve_block(block_id)
end

--- Returns the content of the note file if exist and nil if it does not
---
---@return string[]|?
Note.read_note = function(self)
if self:exists() then
local contents = {}

with(open(tostring(self.path), "r"), function(reader)
local line = reader:read()
while line ~= nil do
line = reader:read()
table.insert(contents, line)
end
end)
return contents
end
end

return Note