feat(diary): restore diary_start_week_day via configurable weekly naming
c63ec67 dropped diary_start_week_day, hardwiring the weekly diary to ISO
(Monday) weeks. Upstream vimwiki instead names a weekly note by the
week-start day's date (YYYY-MM-DD) and honours diary_start_week_day. Rather
than force one scheme, make it a per-wiki choice so migrators keep upstream
behaviour while existing nuwiki weekly files keep working:
- New per-wiki key `diary_weekly_style`: `iso` (default — `YYYY-Www`,
Monday-based, nuwiki's original) or `date`/`vimwiki` (`YYYY-MM-DD` of the
week-start day, upstream parity).
- Restored per-wiki key `diary_start_week_day` (`monday`..`sunday`, default
monday); applies only in `date` mode.
Implementation:
- nuwiki-core::date gains WeeklyStyle, WeekStart, and DiaryCalendar (owns
today/next/prev — date-mode snaps to the week-start and steps ±7 days;
iso/daily/monthly/yearly defer to the existing DiaryPeriod logic).
- WikiConfig gains the two fields (+ defaults, RawWiki, From) and a
diary_calendar() builder; commands.rs diary_open_relative and the
next/prev pivot use it.
Defaults preserve current behaviour (iso/monday), so no breaking change.
Tests: DiaryCalendar cases in nuwiki-core/tests/diary.rs (snap, ±7, sunday
start, iso delegation, daily) + config round-trip in
nuwiki-lsp/tests/index_and_config.rs. README + doc/nuwiki.txt + lua config
comment updated. fmt + clippy clean; all crate tests + config-parity green.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -41,6 +41,14 @@ pub struct WikiConfig {
|
||||
/// diary commands use. `daily` is supported; the others fall through
|
||||
/// to vimwiki-style names but the commands are no-ops for them.
|
||||
pub diary_frequency: String,
|
||||
/// Weekly-diary naming: `iso` (nuwiki default — `YYYY-Www` labels,
|
||||
/// always Monday-based) or `date`/`vimwiki` (the week-start day's date
|
||||
/// `YYYY-MM-DD`, honouring `diary_start_week_day`). Only affects
|
||||
/// `diary_frequency = weekly`.
|
||||
pub diary_weekly_style: String,
|
||||
/// Weekday the diary week begins on (`monday`..`sunday`, vimwiki's
|
||||
/// `diary_start_week_day`). Used only when `diary_weekly_style = date`.
|
||||
pub diary_start_week_day: String,
|
||||
/// Caption level for the diary index page headings (1 = h1).
|
||||
pub diary_caption_level: u8,
|
||||
/// Newest-first (`desc`) or oldest-first (`asc`) in the diary
|
||||
@@ -174,6 +182,8 @@ impl WikiConfig {
|
||||
diary_rel_path: d.diary_rel_path,
|
||||
diary_index: d.diary_index,
|
||||
diary_frequency: d.diary_frequency,
|
||||
diary_weekly_style: d.diary_weekly_style,
|
||||
diary_start_week_day: d.diary_start_week_day,
|
||||
diary_caption_level: d.diary_caption_level,
|
||||
diary_sort: d.diary_sort,
|
||||
diary_header: d.diary_header,
|
||||
@@ -201,6 +211,8 @@ impl WikiConfig {
|
||||
diary_rel_path: d.diary_rel_path,
|
||||
diary_index: d.diary_index,
|
||||
diary_frequency: d.diary_frequency,
|
||||
diary_weekly_style: d.diary_weekly_style,
|
||||
diary_start_week_day: d.diary_start_week_day,
|
||||
diary_caption_level: d.diary_caption_level,
|
||||
diary_sort: d.diary_sort,
|
||||
diary_header: d.diary_header,
|
||||
@@ -245,6 +257,16 @@ impl WikiConfig {
|
||||
pub fn frequency(&self) -> nuwiki_core::date::DiaryFrequency {
|
||||
nuwiki_core::date::DiaryFrequency::parse(&self.diary_frequency)
|
||||
}
|
||||
|
||||
/// The diary navigation policy (frequency + weekly naming/week-start),
|
||||
/// used by the diary commands to compute today / next / prev.
|
||||
pub fn diary_calendar(&self) -> nuwiki_core::date::DiaryCalendar {
|
||||
nuwiki_core::date::DiaryCalendar::new(
|
||||
self.frequency(),
|
||||
nuwiki_core::date::WeeklyStyle::parse(&self.diary_weekly_style),
|
||||
nuwiki_core::date::WeekStart::parse(&self.diary_start_week_day),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fn default_diary_rel_path() -> String {
|
||||
@@ -263,6 +285,15 @@ fn default_diary_frequency() -> String {
|
||||
"daily".to_string()
|
||||
}
|
||||
|
||||
fn default_diary_weekly_style() -> String {
|
||||
// nuwiki's original ISO-week labels; opt into `date` for vimwiki parity.
|
||||
"iso".to_string()
|
||||
}
|
||||
|
||||
fn default_diary_start_week_day() -> String {
|
||||
"monday".to_string()
|
||||
}
|
||||
|
||||
fn default_diary_sort() -> String {
|
||||
"desc".to_string()
|
||||
}
|
||||
@@ -288,6 +319,8 @@ fn wiki_defaults() -> WikiDefaults {
|
||||
diary_rel_path: default_diary_rel_path(),
|
||||
diary_index: default_diary_index(),
|
||||
diary_frequency: default_diary_frequency(),
|
||||
diary_weekly_style: default_diary_weekly_style(),
|
||||
diary_start_week_day: default_diary_start_week_day(),
|
||||
// Match upstream vimwiki's `diary_caption_level` default of 0 (year
|
||||
// captions at the top level, months one below). Users override per-wiki.
|
||||
diary_caption_level: 0,
|
||||
@@ -306,6 +339,8 @@ struct WikiDefaults {
|
||||
diary_rel_path: String,
|
||||
diary_index: String,
|
||||
diary_frequency: String,
|
||||
diary_weekly_style: String,
|
||||
diary_start_week_day: String,
|
||||
diary_caption_level: u8,
|
||||
diary_sort: String,
|
||||
diary_header: String,
|
||||
@@ -519,6 +554,10 @@ struct RawWiki {
|
||||
#[serde(default)]
|
||||
diary_frequency: Option<String>,
|
||||
#[serde(default)]
|
||||
diary_weekly_style: Option<String>,
|
||||
#[serde(default)]
|
||||
diary_start_week_day: Option<String>,
|
||||
#[serde(default)]
|
||||
diary_caption_level: Option<u8>,
|
||||
#[serde(default)]
|
||||
diary_sort: Option<String>,
|
||||
@@ -584,6 +623,8 @@ impl From<RawWiki> for WikiConfig {
|
||||
diary_rel_path: r.diary_rel_path.unwrap_or(d.diary_rel_path),
|
||||
diary_index: r.diary_index.unwrap_or(d.diary_index),
|
||||
diary_frequency: r.diary_frequency.unwrap_or(d.diary_frequency),
|
||||
diary_weekly_style: r.diary_weekly_style.unwrap_or(d.diary_weekly_style),
|
||||
diary_start_week_day: r.diary_start_week_day.unwrap_or(d.diary_start_week_day),
|
||||
diary_caption_level: r.diary_caption_level.unwrap_or(d.diary_caption_level),
|
||||
diary_sort: r.diary_sort.unwrap_or(d.diary_sort),
|
||||
diary_header: r.diary_header.unwrap_or(d.diary_header),
|
||||
|
||||
Reference in New Issue
Block a user