-
Notifications
You must be signed in to change notification settings - Fork 189
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
How would I go about creating a default tag on new note? #173
Comments
Hey @mesa123123, you could accomplish this by customizing the
|
Hey @epwalsh been giving that a crack and my tags aren't changing: This is my frontmatter function: local make_note_frontmatter = function(note)
local out = { tags = "todo"}
return out
end so my fontmatter should be something along the lines of: ---
id: "Note"
aliases:
- "Note"
tags:
- "todo"
--- Instead its still: ---
id: "Note"
aliases:
- "Note"
tags: []
--- What value would you need to give tags to change it? Ive tried: -- Attempt 1
out = { tags = "todo"}
-- Attempt 2
tags = { "todo" }
note.tags.insert(tags)
-- Attempt 3
default_tags = {"todo"}
out = { tags = default_tags }
-- Attempt 4
default_tags = function()
return { "todo" }
end
out = {tags = default_tags()}
-- Attempt 5
default_tags = function()
return { "todo" }
end
out = {tags = default_tags} Could you tell where I'm going wrong? |
Ok so looking through note.lua I think this is what updates the tags based on the front matter?? elseif k == "tags" then
if type(v) == "table" then
for _, tag in ipairs(v) do
if type(tag) == "string" then
table.insert(tags, tag)
else
echo.warn(
"Invalid tag value found in frontmatter for "
.. path
.. ". Expected string, found "
.. type(tag)
.. "."
)
end
end So knowing that didn't help me too much: ---
id: "DidThisWork?"
aliases:
- "DidThisWork?"
tags: []
---
W # DidThisWork? local make_note_frontmatter = function(note)
local out = { tags = { "todo" } }
return out
end
-- Setup
----------
require("obsidian").setup({
dir = "~/Learning",
templates = {
subdir = "templates",
date_format = "%Y-%m-%d-%a",
time_format = "%H:%M",
},
mappings = {},
note_id_func = make_note_id,
note_frontmatter_func = make_note_frontmatter
})
----------
|
Would calling this method somehow help? --- Line 86 Note.lua ---
---Add a tag to the note.
---
---@param tag string
note.add_tag = function(self, tag)
if not self:has_tag(tag) then
table.insert(self.tags, tag)
end
end |
Hey @mesa123123, sorry for the slow response. I think you're right about calling note_frontmatter_func = function(note)
note:add_tag "TODO"
local out = { id = note.id, aliases = note.aliases, tags = note.tags }
-- `note.metadata` contains any manually added fields in the frontmatter.
-- So here we just make sure those fields are kept in the frontmatter.
if note.metadata ~= nil and require("obsidian").util.table_length(note.metadata) > 0 then
for k, v in pairs(note.metadata) do
out[k] = v
end
end
return out
end, |
Brilliant, sorry for the slow response on my end too, I'll give that a try now and see if i can recreate it |
Doesn't appear to be working sadly! Is there somethig that might be blocking it? I've tried for both link under cursor and regular create functions |
Fixes #173 The configuration option `note_frontmatter_func` will now be used when creating new notes.
Ah I see the issue! #178 should fix. |
Fixes #173 The configuration option `note_frontmatter_func` will now be used when creating new notes.
…h#178) Closes epwalsh#175 Closes epwalsh#177 Closes epwalsh#173 Closes epwalsh#169 Closes epwalsh#161 Closes epwalsh#144 Closes epwalsh#138 Fixes epwalsh#136 Closes epwalsh#137 Closes epwalsh#131 Closes epwalsh#117 Closes epwalsh#130 Closes epwalsh#115 Closes epwalsh#86 Closes epwalsh#105 Closes epwalsh#70 Fixes epwalsh#176 Fixes epwalsh#174 Fixes epwalsh#160 Fixes epwalsh#158
Hey @epwalsh just wondering if you have a similar bug where a daily note upon being saved ends up adding the default tag to the note. Is there a way to solve this issue? Let me know! It could just be my config messing things up |
Hey @mesa123123, sorry just getting back to this now. Are you saying that when you make a new daily note it's missing the extra tag? |
📚 The doc issue
I'm creating notes left and right using this and theres heaps of blank notes in my vault, I want to know which ones are blank so I can go back and rewrite them later on, so I'm thinking everytime I create a note could it have a default tag of "TODO" or something akin?
After reading the code a bit I'm guessing it has something to do with the note_id_func option and inserting something like { title = "title", tags = { "TODO" } }?
Thought I'd ask as I'm a little stumped as my lua is not as sharp as I'd like?
Am I on the right track?
Suggest a potential alternative/fix
No response
The text was updated successfully, but these errors were encountered: