diff options
| author | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-07-27 13:20:28 +0200 |
|---|---|---|
| committer | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-07-27 13:20:28 +0200 |
| commit | aaa1c702124a6f0044b458482b349dc725816674 (patch) | |
| tree | 78bd166c4dea5778c6951613f3105c06f1f80ffd | |
| parent | acbba6b53df93de694abf1feb90ab401fd6a4580 (diff) | |
| download | lectio-aaa1c702124a6f0044b458482b349dc725816674.tar.gz lectio-aaa1c702124a6f0044b458482b349dc725816674.zip | |
feat(config): 'use' layer stack + CalendarsDir()
| -rw-r--r-- | internal/config/config.go | 19 | ||||
| -rw-r--r-- | internal/config/config_test.go | 21 |
2 files changed, 40 insertions, 0 deletions
diff --git a/internal/config/config.go b/internal/config/config.go index bf46224..2fb4daa 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -45,6 +45,8 @@ const configHeader = `# lectio configuration (INI). Full-line comments only (# o # web_mono true | false (monospace reading face in the web UI) # web_versions any of: bt, wuj, vul, grb, drb (comma list); empty = just default_version # pager shell command, e.g. less -R; empty = off +# use calendar layers to stack over the universal calendar: names of +# ~/.config/lectio/calendars/<name>.ini files (comma list, order = precedence) # # [calendar] — computed-calendar placement options (defaults = Universal Roman Calendar): # epiphany fixed | sunday (fixed = Jan 6; sunday = the Sunday of Jan 2-8) @@ -165,6 +167,10 @@ type Config struct { CalEpiphany string `toml:"-"` CalAscension string `toml:"-"` CalCorpusChristi string `toml:"-"` + + // Use is the ordered stack of user calendar-layer ids (INI "use"); each id + // names a <CalendarsDir>/<id>.ini file layered over the universal calendar. + Use []string `toml:"-"` } // PartShown reports whether a part renders: true unless explicitly set false. @@ -254,6 +260,16 @@ func configPath() (path string, isDefault bool, err error) { return filepath.Join(dir, "lectio", "config.ini"), true, nil } +// CalendarsDir returns the directory holding user calendar-layer files +// (<config dir>/calendars). +func CalendarsDir() (string, error) { + p, _, err := configPath() + if err != nil { + return "", err + } + return filepath.Join(filepath.Dir(p), "calendars"), nil +} + // BooksPath returns the path to the optional user books.toml (in the same // directory as the config file). There is no embedded seed on disk -- absence // means "use the built-in defaults". @@ -438,6 +454,8 @@ func applyScalar(cfg *Config, key, val string) { cfg.WebVersions = ini.List(val) case "pager": cfg.Pager = val + case "use": + cfg.Use = ini.List(val) } } @@ -511,6 +529,7 @@ func renderConfigINI(cfg Config) []byte { fmt.Fprintf(&b, "web_mono = %t\n", cfg.WebMono) fmt.Fprintf(&b, "web_versions = %s\n", strings.Join(cfg.WebVersions, ", ")) fmt.Fprintf(&b, "pager = %s\n", cfg.Pager) + fmt.Fprintf(&b, "use = %s\n", strings.Join(cfg.Use, ", ")) b.WriteString("\n# Computed-calendar national placement options.\n[calendar]\n") fmt.Fprintf(&b, "epiphany = %s\n", orDefault(cfg.CalEpiphany, "fixed")) diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 38c7604..e3af475 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -239,6 +239,27 @@ func TestSelectionFromINI(t *testing.T) { } } +func TestUseLayers(t *testing.T) { + dir := t.TempDir() + t.Setenv("LECTIO_CONFIG", filepath.Join(dir, "config.ini")) + os.WriteFile(filepath.Join(dir, "config.ini"), []byte("use = poland, krakow\n"), 0o644) + cfg, err := Load() + if err != nil { + t.Fatal(err) + } + if len(cfg.Use) != 2 || cfg.Use[0] != "poland" || cfg.Use[1] != "krakow" { + t.Fatalf("Use = %v", cfg.Use) + } + // round-trips through Save + if err := Save(cfg); err != nil { + t.Fatal(err) + } + got, _ := Load() + if len(got.Use) != 2 || got.Use[1] != "krakow" { + t.Errorf("Use after round-trip = %v", got.Use) + } +} + func TestMigrateTOMLToINI(t *testing.T) { dir := t.TempDir() t.Setenv("XDG_CONFIG_HOME", dir) |
