feat(config): on-save autoregen family — links/tags/diary-index (P2)
Added per-wiki auto_generate_links, auto_generate_tags, auto_diary_index (default false, like upstream), wired into the did_save hook mirroring auto_toc: - auto_generate_links / auto_generate_tags rebuild the Generated Links / Generated Tags section ONLY when it already exists (new links_rebuild_edit / tag_links_rebuild_edit, like toc_rebuild_edit) — never inserts one into a page that lacks it. - auto_diary_index regenerates the diary index page when a dated diary entry (not the index itself) is saved, via diary_generate_index_edit (handles the index file open / on-disk / absent). auto_tags is recorded as an intentional divergence: nuwiki re-indexes tags on every change, so the tag metadata is always fresh (no on-disk file to update). Tests: links_rebuild_edit_only_acts_when_section_present, tag_links_rebuild_edit_only_acts_when_index_present, config round-trip + defaults. README/doc/lua comment updated. fmt/clippy clean; 0 Rust failures. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -75,6 +75,15 @@ pub struct WikiConfig {
|
||||
pub links_space_char: String,
|
||||
/// Rebuild the page's TOC on save when set.
|
||||
pub auto_toc: bool,
|
||||
/// On save, regenerate an existing `Generated Links` section
|
||||
/// (vimwiki's `auto_generate_links`).
|
||||
pub auto_generate_links: bool,
|
||||
/// On save, regenerate an existing `Generated Tags` index section
|
||||
/// (vimwiki's `auto_generate_tags`).
|
||||
pub auto_generate_tags: bool,
|
||||
/// On save of a diary entry, regenerate the diary index page
|
||||
/// (vimwiki's `auto_diary_index`).
|
||||
pub auto_diary_index: bool,
|
||||
/// Heading text + level for the generated `:VimwikiTOC` section
|
||||
/// (vimwiki's `toc_header` / `toc_header_level`).
|
||||
pub toc_header: String,
|
||||
@@ -208,6 +217,9 @@ impl WikiConfig {
|
||||
list_margin: d.list_margin,
|
||||
links_space_char: d.links_space_char,
|
||||
auto_toc: d.auto_toc,
|
||||
auto_generate_links: d.auto_generate_links,
|
||||
auto_generate_tags: d.auto_generate_tags,
|
||||
auto_diary_index: d.auto_diary_index,
|
||||
toc_header: d.toc_header,
|
||||
toc_header_level: d.toc_header_level,
|
||||
links_header: d.links_header,
|
||||
@@ -244,6 +256,9 @@ impl WikiConfig {
|
||||
list_margin: d.list_margin,
|
||||
links_space_char: d.links_space_char,
|
||||
auto_toc: d.auto_toc,
|
||||
auto_generate_links: d.auto_generate_links,
|
||||
auto_generate_tags: d.auto_generate_tags,
|
||||
auto_diary_index: d.auto_diary_index,
|
||||
toc_header: d.toc_header,
|
||||
toc_header_level: d.toc_header_level,
|
||||
links_header: d.links_header,
|
||||
@@ -384,6 +399,9 @@ fn wiki_defaults() -> WikiDefaults {
|
||||
list_margin: -1,
|
||||
links_space_char: default_links_space_char(),
|
||||
auto_toc: false,
|
||||
auto_generate_links: false,
|
||||
auto_generate_tags: false,
|
||||
auto_diary_index: false,
|
||||
toc_header: default_toc_header(),
|
||||
toc_header_level: 1,
|
||||
links_header: default_links_header(),
|
||||
@@ -409,6 +427,9 @@ struct WikiDefaults {
|
||||
list_margin: i32,
|
||||
links_space_char: String,
|
||||
auto_toc: bool,
|
||||
auto_generate_links: bool,
|
||||
auto_generate_tags: bool,
|
||||
auto_diary_index: bool,
|
||||
toc_header: String,
|
||||
toc_header_level: u8,
|
||||
links_header: String,
|
||||
@@ -641,6 +662,12 @@ struct RawWiki {
|
||||
links_space_char: Option<String>,
|
||||
#[serde(default, deserialize_with = "opt_bool_or_int::deserialize")]
|
||||
auto_toc: Option<bool>,
|
||||
#[serde(default, deserialize_with = "opt_bool_or_int::deserialize")]
|
||||
auto_generate_links: Option<bool>,
|
||||
#[serde(default, deserialize_with = "opt_bool_or_int::deserialize")]
|
||||
auto_generate_tags: Option<bool>,
|
||||
#[serde(default, deserialize_with = "opt_bool_or_int::deserialize")]
|
||||
auto_diary_index: Option<bool>,
|
||||
#[serde(default)]
|
||||
toc_header: Option<String>,
|
||||
#[serde(default)]
|
||||
@@ -714,6 +741,9 @@ impl From<RawWiki> for WikiConfig {
|
||||
list_margin: r.list_margin.unwrap_or(d.list_margin),
|
||||
links_space_char: r.links_space_char.unwrap_or(d.links_space_char),
|
||||
auto_toc: r.auto_toc.unwrap_or(d.auto_toc),
|
||||
auto_generate_links: r.auto_generate_links.unwrap_or(d.auto_generate_links),
|
||||
auto_generate_tags: r.auto_generate_tags.unwrap_or(d.auto_generate_tags),
|
||||
auto_diary_index: r.auto_diary_index.unwrap_or(d.auto_diary_index),
|
||||
toc_header: r.toc_header.unwrap_or(d.toc_header),
|
||||
toc_header_level: r.toc_header_level.unwrap_or(d.toc_header_level),
|
||||
links_header: r.links_header.unwrap_or(d.links_header),
|
||||
|
||||
Reference in New Issue
Block a user