Skip to content

Commit

Permalink
Update .config/nvim/lua/plugins/obsidian.lua
Browse files Browse the repository at this point in the history
  • Loading branch information
Hyuga-Tsukui committed Feb 3, 2025
1 parent e6a39f9 commit 96c33d4
Showing 1 changed file with 53 additions and 51 deletions.
104 changes: 53 additions & 51 deletions dot_config/nvim/lua/plugins/obsidian.lua
Original file line number Diff line number Diff line change
@@ -1,70 +1,72 @@
local cmd = {
"ObsidianNew",
"ObsidianSearch",
"ObsidianNew",
"ObsidianSearch",
}

local rules = {
{ pattern = "[%s /\\?*]", replace = "-" },
{ pattern = "[%s /\\?*]", replace = "-" },
}

-- Replace all characters in a string that match a pattern.
-- @param s string: The string to replace characters in.
-- @return string: The string with characters replaced.
local replace = function(s)
for _, rule in ipairs(rules) do
s = s:gsub(rule.pattern, rule.replace)
end
return s
for _, rule in ipairs(rules) do
s = s:gsub(rule.pattern, rule.replace)
end
return s
end

local opts = {
workspaces = {
{
name = "personal",
path = vim.fn.expand("~/obsidian"),
},
},
notes_subdir = "inbox",
-- disable_frontmatter = true,
note_id_func = function(title)
-- Create note IDs in a Zettelkasten format with a timestamp and a suffix.
-- In this case a note with the title 'My new note' will be given an ID that looks
-- like '1657296016-my-new-note', and therefore the file name '1657296016-my-new-note.md'
local suffix = ""
if title ~= nil then
-- If title is given, transform it into valid file name.
suffix = replace(title)
else
-- If title is nil, just add 4 random uppercase letters to the suffix.
for _ = 1, 4 do
suffix = suffix .. string.char(math.random(65, 90))
end
end
return tostring(os.time()) .. "-" .. suffix
end,
workspaces = {
{
name = "personal",
path = vim.fn.expand("~/obsidian"),
},
},
notes_subdir = "000_zettelkasten",
disable_frontmatter = true,
note_id_func = function(title)
-- Create note IDs in a Zettelkasten format with a timestamp and a suffix.
-- In this case a note with the title 'My new note' will be given an ID that looks
-- like '1657296016-my-new-note', and therefore the file name '1657296016-my-new-note.md'

note_path_func = function(spec)
local file_name = ""
if spec.title ~= nil then
file_name = replace(spec.title)
else
file_name = spec.id
end
return (spec.dir / file_name):with_suffix(".md")
end,
print(title)
local suffix = ""
if title ~= nil then
-- If title is given, transform it into valid file name.
suffix = replace(title)
else
-- If title is nil, just add 4 random uppercase letters to the suffix.
for _ = 1, 4 do
suffix = suffix .. string.char(math.random(65, 90))
end
end
return suffix
end,

picker = {
name = "fzf-lua",
},
note_path_func = function(spec)
local file_name = ""
if spec.title ~= nil then
file_name = replace(spec.title)
else
file_name = spec.id
end
return (spec.dir / file_name):with_suffix(".md")
end,

picker = {
name = "fzf-lua",
},
}

return {
"epwalsh/obsidian.nvim",
cmd = cmd,
dependencies = {
"nvim-lua/plenary.nvim",
"ibhagwan/fzf-lua",
"hrsh7th/nvim-cmp",
},
opts = opts,
"epwalsh/obsidian.nvim",
cmd = cmd,
dependencies = {
"nvim-lua/plenary.nvim",
"ibhagwan/fzf-lua",
"hrsh7th/nvim-cmp",
},
opts = opts,
}

0 comments on commit 96c33d4

Please sign in to comment.