From d5d175118138249fe7d9e85d1bc65fb0b7e3a398 Mon Sep 17 00:00:00 2001 From: Lukasz Kasprzak Date: Tue, 28 Jul 2026 19:22:40 +0200 Subject: caldata: allow an external universal sanctorale to override the embedded one The universal calendar of saints can now be refreshed or replaced without a rebuild: if ~/.config/lectio/sanctorale/of.ini (OF) or ef.ini (EF) is present and parses, caldata.Base uses it instead of the embedded calendar; a missing or malformed file falls back to the embedded default, so the binary stays self-contained and correct out of the box. Local diocesan/national additions keep layering on top via calendars/ + `use` (unchanged). The temporal cycle and precedence rules stay in code -- only the sanctorale is data. - caldata.SetSanctoraleDir hook (mirrors bible/naming/i18n); Base() prefers the external file per form. config.SanctoraleDir(); wired in the CLI, TUI and web entry points. Tests cover override, no-file, and malformed-file fallback. - README: new "Calendar of saints" section (two tiers: overlay via `use`, replace via sanctorale/
.ini); config comment notes the override. --- internal/caldata/caldata.go | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'internal/caldata/caldata.go') diff --git a/internal/caldata/caldata.go b/internal/caldata/caldata.go index 9c17035..4e54f1f 100644 --- a/internal/caldata/caldata.go +++ b/internal/caldata/caldata.go @@ -77,9 +77,34 @@ func Tridentine() calendar.Layer { return l } +// sanctoraleDir, when set, holds an optional external universal sanctorale that +// overrides the embedded one (of.ini for OF, ef.ini for EF). Set once at startup +// via SetSanctoraleDir; empty means "use the embedded calendar". +var sanctoraleDir string + +// SetSanctoraleDir points caldata at the dir holding an optional external +// universal sanctorale (/of.ini, /ef.ini). Empty disables it. +func SetSanctoraleDir(dir string) { sanctoraleDir = dir } + // Base returns the universal base layer for a form: the 1962 calendar for -// "old" (EF), the General Roman Calendar otherwise (OF). +// "old" (EF), the General Roman Calendar otherwise (OF). If an external +// sanctorale file is present and parses, it REPLACES the embedded calendar for +// that form -- so the saints and ranks can be updated without a rebuild. A +// missing or malformed external file falls back to the embedded default, which +// therefore always keeps the tool self-contained and correct out of the box. func Base(form string) calendar.Layer { + if sanctoraleDir != "" { + name := "of.ini" + if form == "old" { + name = "ef.ini" + } + if data, err := os.ReadFile(filepath.Join(sanctoraleDir, name)); err == nil { + if l, err := ParseLayer(data); err == nil { + return l + } + // malformed external file: fall through to the embedded default + } + } if form == "old" { return Tridentine() } -- cgit v1.3