-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update .config/nvim/lua/plugins/obsidian.lua
- Loading branch information
1 parent
e6a39f9
commit 96c33d4
Showing
1 changed file
with
53 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} |