aboutsummaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authormoxie <moxie@3kgcat.fi>2026-03-15 06:41:37 +0200
committermoxie <moxie@3kgcat.fi>2026-03-15 10:05:06 +0200
commit49c1e9d1fc3d6bf8748756a8543d8c1b7287940f (patch)
tree8e03c663f10c2a0a17b44bef6a3dbf575582fb2c /doc
parentc8dc1635f8a921269f714117f414bbc7ba24f9fd (diff)
refactor: move template/mkdir features to user-configured autocmds
- Remove auto-mkdir autocmd from init.lua (now user-configured) - Remove template system entirely (now user-configured) - Rename io.lua -> utils.lua - Inline single-use functions (handle_web_link, handle_file_link, etc.) - Remove security warnings for external files - Remove unused config options: use_template, template, date_fmt - Simplify utils.resolve() without wiki root validation - Update all documentation examples BREAKING CHANGE: Users must now add their own autocmds for: - Auto-creating directories on save (BufWritePre) - Applying templates to new files (BufNewFile) See README.md for updated configuration examples.
Diffstat (limited to 'doc')
-rw-r--r--doc/muwiki.txt134
-rw-r--r--doc/tags1
2 files changed, 69 insertions, 66 deletions
diff --git a/doc/muwiki.txt b/doc/muwiki.txt
index 4576388..878095d 100644
--- a/doc/muwiki.txt
+++ b/doc/muwiki.txt
@@ -12,7 +12,6 @@ CONTENTS *muwiki-contents*
5. Keymaps ................................ |muwiki-keymaps|
6. Link Format ............................ |muwiki-link-format|
7. External Handlers ...................... |muwiki-external-handlers|
-8. Templates .............................. |muwiki-templates|
==============================================================================
1. INTRODUCTION *muwiki-introduction*
@@ -24,7 +23,6 @@ Features:~
- Standard markdown links `[text](url)`
- Multiple wiki directories support
- External link handlers for custom URL/file opening
-- Automatic templates for new pages
- Link navigation with custom keymaps
Requirements:~
@@ -51,20 +49,39 @@ Using lazy.nvim:~
local muwiki = require('muwiki')
muwiki.setup(opts)
- local group = vim.api.nvim_create_augroup("MuWikiKeymaps", { clear = true })
+ local group = vim.api.nvim_create_augroup("muwiki", { clear = true })
+ -- Setup wiki keymaps for markdown files
vim.api.nvim_create_autocmd("FileType", {
group = group,
pattern = "markdown",
- callback = function(ev)
- if not muwiki.wiki_root(ev.buf) then return end
- local keymap_opts = { buffer = ev.buf, silent = true, nowait = true }
+ callback = function(args)
+ if not muwiki.wiki_root(args.buf) then return end
+
+ local keymap_opts = { buffer = args.buf, silent = true, nowait = true }
vim.keymap.set('n', '<CR>', muwiki.open_link, keymap_opts)
vim.keymap.set('n', '<Tab>', muwiki.next_link, keymap_opts)
vim.keymap.set('n', '<S-Tab>', muwiki.prev_link, keymap_opts)
vim.keymap.set('v', '<CR>', muwiki.create_link, keymap_opts)
end,
})
+
+ -- Auto-create parent directories when saving files in wiki
+ vim.api.nvim_create_autocmd("BufWritePre", {
+ group = group,
+ callback = function(args)
+ local wiki_root = muwiki.wiki_root(args.buf)
+ if not wiki_root then return end
+
+ local file = args.file
+ if not vim.startswith(file, wiki_root) then return end
+
+ local dir = vim.fn.fnamemodify(file, ":h")
+ if vim.fn.isdirectory(dir) == 0 then
+ vim.fn.mkdir(dir, "p")
+ end
+ end,
+ })
end,
}
<
@@ -79,15 +96,6 @@ Configuration Options:~
index_file Name of the wiki index file
Default: 'index.md'
- date_fmt Date format string for templates
- Default: '%Y-%m-%d'
-
- use_template Enable automatic templates for new pages
- Default: false
-
- template Template content with placeholders
- See |muwiki-templates|
-
use_external_handlers Enable external URL/file handlers
Default: false
@@ -101,15 +109,6 @@ Configuration Options:~
to force editor opening.
Default: { 'md', 'txt' }
- create_missing_dirs Automatically create missing parent directories
- when opening or creating wiki files.
- Values:
- false - Don't create directories (default)
- 'notify' - Create and show notification
- 'prompt' - Ask before creating
- Directories are only created within wiki root.
- Default: false
-
Example:~
>lua
{
@@ -124,15 +123,6 @@ Example:~
{ name = 'test', path = '~/wiki_test' },
},
index_file = 'index.md',
- create_missing_dirs = 'notify',
- date_fmt = '%Y-%m-%d',
- use_template = true,
- template = [[
- ---
- title: ${title}
- date: ${date}
- ---
- ]],
text_extensions = { 'md', 'txt' },
use_external_handlers = true,
external_handlers = {
@@ -168,14 +158,16 @@ Example:~
local muwiki = require('muwiki')
muwiki.setup(opts)
- local group = vim.api.nvim_create_augroup("MuWikiKeymaps", { clear = true })
+ local group = vim.api.nvim_create_augroup("muwiki", { clear = true })
+ -- Setup wiki keymaps for markdown files
vim.api.nvim_create_autocmd("FileType", {
group = group,
pattern = "markdown",
- callback = function(ev)
- if not muwiki.wiki_root(ev.buf) then return end
- local keymap_opts = { buffer = ev.buf, silent = true, nowait = true }
+ callback = function(args)
+ if not muwiki.wiki_root(args.buf) then return end
+
+ local keymap_opts = { buffer = args.buf, silent = true, nowait = true }
vim.keymap.set('n', '<CR>', muwiki.open_link, keymap_opts)
vim.keymap.set('n', '<Tab>', muwiki.next_link, keymap_opts)
vim.keymap.set('n', '<S-Tab>', muwiki.prev_link, keymap_opts)
@@ -183,6 +175,23 @@ Example:~
vim.keymap.set('n', '<leader>oo', muwiki.open_link_with, keymap_opts)
end,
})
+
+ -- Auto-create parent directories when saving files in wiki
+ vim.api.nvim_create_autocmd("BufWritePre", {
+ group = group,
+ callback = function(args)
+ local wiki_root = muwiki.wiki_root(args.buf)
+ if not wiki_root then return end
+
+ local file = args.file
+ if not vim.startswith(file, wiki_root) then return end
+
+ local dir = vim.fn.fnamemodify(file, ":h")
+ if vim.fn.isdirectory(dir) == 0 then
+ vim.fn.mkdir(dir, "p")
+ end
+ end,
+ })
end,
}
<
@@ -277,14 +286,16 @@ Configure keymaps using an autocmd to ensure they only apply within wiki
directories: >lua
local muwiki = require('muwiki')
- local group = vim.api.nvim_create_augroup("MuWikiKeymaps", { clear = true })
+ local group = vim.api.nvim_create_augroup("muwiki", { clear = true })
+ -- Setup wiki keymaps for markdown files
vim.api.nvim_create_autocmd("FileType", {
group = group,
pattern = "markdown",
- callback = function(ev)
- if not muwiki.wiki_root(ev.buf) then return end
- local opts = { buffer = ev.buf, silent = true, nowait = true }
+ callback = function(args)
+ if not muwiki.wiki_root(args.buf) then return end
+
+ local opts = { buffer = args.buf, silent = true, nowait = true }
vim.keymap.set('n', '<CR>', muwiki.open_link, opts)
vim.keymap.set('n', '<Tab>', muwiki.next_link, opts)
vim.keymap.set('n', '<S-Tab>', muwiki.prev_link, opts)
@@ -292,6 +303,23 @@ directories: >lua
vim.keymap.set('n', '<leader>oo', muwiki.open_link_with, opts)
end,
})
+
+ -- Auto-create parent directories when saving files in wiki
+ vim.api.nvim_create_autocmd("BufWritePre", {
+ group = group,
+ callback = function(args)
+ local wiki_root = muwiki.wiki_root(args.buf)
+ if not wiki_root then return end
+
+ local file = args.file
+ if not vim.startswith(file, wiki_root) then return end
+
+ local dir = vim.fn.fnamemodify(file, ":h")
+ if vim.fn.isdirectory(dir) == 0 then
+ vim.fn.mkdir(dir, "p")
+ end
+ end,
+ })
<
Note: Actions check if the buffer is within a configured wiki directory and
notify the user if not.
@@ -409,30 +437,6 @@ Example: Open PNG files in Neovim (as text/hex) instead of external viewer:~
text_extensions = { 'md', 'txt', 'png' }
<
==============================================================================
-8. TEMPLATES *muwiki-templates*
-
-Automatic templates can be applied when creating new wiki pages.
-
-Enable templates:~
->lua
- require("muwiki").setup({
- use_template = true,
- })
-<
-Template Placeholders:~
-
- ${title} Page title (derived from filename)
- ${date} Current date (formatted with `date_fmt`)
-
-Default Template:~
->lua
- template = [[
----
-title: ${title}
-date: ${date}
----
-]]
-<
==============================================================================
HEALTH CHECKING *muwiki-health*
diff --git a/doc/tags b/doc/tags
index f52890d..300649b 100644
--- a/doc/tags
+++ b/doc/tags
@@ -7,7 +7,6 @@ muwiki-installation muwiki.txt /*muwiki-installation*
muwiki-introduction muwiki.txt /*muwiki-introduction*
muwiki-keymaps muwiki.txt /*muwiki-keymaps*
muwiki-link-format muwiki.txt /*muwiki-link-format*
-muwiki-templates muwiki.txt /*muwiki-templates*
muwiki.next_link() muwiki.txt /*muwiki.next_link()*
muwiki.open_index() muwiki.txt /*muwiki.open_index()*
muwiki.open_link() muwiki.txt /*muwiki.open_link()*