commit 13867a1b216b15085c4afb94772c7cea13b55e37
parent e5ee58a717143ba40f5e2f6945759eba78a698fc
Author: Oscar Benedito <oscar@oscarbenedito.com>
Date:   Sun, 30 Jan 2022 19:05:11 +0100

Updates to vimwiki config and HTML generation

Diffstat:
M.config/nvim/lua/plugins.lua | 20++++++++++++++------
M.local/share/vimwiki/template.html | 6+++++-
M.local/share/vimwiki/wiki2html.py | 15+++++++++------
3 files changed, 28 insertions(+), 13 deletions(-)

diff --git a/.config/nvim/lua/plugins.lua b/.config/nvim/lua/plugins.lua @@ -14,7 +14,7 @@ local ret = require("paq") { do -- vim-commentary vim.cmd [[ - augroup packer_vimcommentary + augroup paq_vimcommentary autocmd! autocmd FileType apache,crontab setlocal commentstring=#\ %s augroup END @@ -37,15 +37,23 @@ end do -- vimwiki - -- first category is used for important meta files to be shown on root, - -- last category is used for uncategorized files - vim.g.vw_categories = { "Arrel", "Notes", "Temporal", "Receptes", "Blog", "Projectes", "Tecnologia", "Programari", "Altres", "Arxiu", "Sense categoria" } + vim.cmd "nmap <Leader>t <Plug>VimwikiVSplitLink" + vim.cmd "nnoremap <Leader>wha :VimwikiAll2HTML<CR>" + + vim.cmd [[ + augroup paq_vimwiki + autocmd! + autocmd FileType vimwiki + \ autocmd! paq_vimwiki BufWritePost <buffer> silent :Vimwiki2HTML + augroup END + ]] vim.g.vimwiki_global_ext = 0 vim.g.vimwiki_folding = "custom" - vim.cmd "nmap <Leader>t <Plug>VimwikiVSplitLink" - vim.cmd "nnoremap <Leader>wha :VimwikiAll2HTML<CR>" + -- first category is used for important meta files to be shown on root, + -- last category is used for uncategorized files + vim.g.vw_categories = { "Arrel", "Notes", "Temporal", "Receptes", "Blog", "Projectes", "Tecnologia", "Programari", "Altres", "Arxiu", "Sense categoria" } local vw_categories_str = "" for _, c in pairs(vim.g.vw_categories) do diff --git a/.local/share/vimwiki/template.html b/.local/share/vimwiki/template.html @@ -8,7 +8,7 @@ <style> body { margin: 1em auto; - max-width: 800px; + max-width: 900px; line-height: 1.5; padding: 0 1em; font-family: sans-serif; @@ -49,6 +49,10 @@ hr { border-top: 2px solid #777; height: 2px; } +li { + margin-top: .25em; + margin-bottom: .25em; +} .header { text-align: center; margin: 2rem 0; diff --git a/.local/share/vimwiki/wiki2html.py b/.local/share/vimwiki/wiki2html.py @@ -81,12 +81,15 @@ def make_toc_file(path, wiki_path, categories): f.write(text) -def href_to_html(match): +def href_to_html(match, wiki_path, root_path): href = match.group(2) - if not re.search('://', match.group(2)): - href += '.html' - if match.group(3): - href += '#' + match.group(3).replace(' ', '-').lower() + if not re.search('://', href): + if re.search('^' + root_path + 'static/', href): # it's a static file, link to it + href = wiki_path + href[len(root_path):] + else: # it's a vimwiki page, link to the output html + href += '.html' + if match.group(3): + href += '#' + match.group(3).replace(' ', '-').lower() return "[{}]({})".format(match.group(1), href) @@ -94,7 +97,7 @@ def wiki_to_html(input_file, output_file, template_file, root_path, wiki_path, c params, text = get_file_metadata_and_text(input_file, wiki_path, categories) # format links for HTML - text = re.sub('\[([^]]+)\]\(([^)#]*)(?:#([^)]*))?\)', href_to_html, text) + text = re.sub('\[([^]]+)\]\(([^)#]*)(?:#([^)]*))?\)', lambda m: href_to_html(m, wiki_path, root_path), text) # add support for TODOs text = re.sub('^([ \t]*- )\[[ .oO]\] ', lambda m : m.group(1) + '<input type="checkbox" disabled> ', text, flags=re.MULTILINE) text = re.sub('^([ \t]*- )\[X\] ', lambda m : m.group(1) + '<input type="checkbox" checked disabled> ', text, flags=re.MULTILINE)