aboutsummaryrefslogtreecommitdiff
path: root/internal/readings/readings.go
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-07-23 13:28:38 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-07-23 13:28:38 +0200
commit0351f4f188207d0204e1e0124d32127e820e33d5 (patch)
tree526ae229dd7a56987cf6f262afbf2d5f0ad53293 /internal/readings/readings.go
parentf8772261f0c4feca68eee0300b5d726fd168a534 (diff)
downloadlectio-0351f4f188207d0204e1e0124d32127e820e33d5.tar.gz
lectio-0351f4f188207d0204e1e0124d32127e820e33d5.zip
readings: lectionary router + part filtering
Diffstat (limited to 'internal/readings/readings.go')
-rw-r--r--internal/readings/readings.go75
1 files changed, 75 insertions, 0 deletions
diff --git a/internal/readings/readings.go b/internal/readings/readings.go
new file mode 100644
index 0000000..886c1eb
--- /dev/null
+++ b/internal/readings/readings.go
@@ -0,0 +1,75 @@
+// Package readings is the single entry point the CLI and TUI use to fetch
+// a day's readings. It routes between the modern (liturgy) and traditional
+// (tradlit) lectionaries by config, then applies part filtering, returning
+// source-agnostic liturgy.Section values either way.
+package readings
+
+import (
+ "fmt"
+
+ "github.com/lukaszkasprzak/lectio/internal/config"
+ "github.com/lukaszkasprzak/lectio/internal/liturgy"
+ "github.com/lukaszkasprzak/lectio/internal/tradlit"
+)
+
+// Options controls how Load resolves a day's readings.
+type Options struct {
+ // Date is the day to load, formatted YYYY-MM-DD.
+ Date string
+ // Refresh bypasses cache layers and re-fetches from the network
+ // (modern lectionary only; see liturgy.Options.Refresh).
+ Refresh bool
+ // Offline restricts Load to previously cached/harvested data, never
+ // hitting the network. Traditional+Offline is not yet supported.
+ Offline bool
+ // All, when true, keeps every part the config doesn't explicitly hide;
+ // when false, only the gospel is kept.
+ All bool
+}
+
+// Load fetches the day's sections for the configured lectionary
+// (cfg.Lectionary: "traditional" or "new") and applies part filtering.
+// Returns liturgy.Section values regardless of source.
+func Load(cfg config.Config, opts Options) ([]liturgy.Section, error) {
+ offline := opts.Offline || cfg.Offline
+
+ var secs []liturgy.Section
+ var err error
+
+ if cfg.Lectionary == "traditional" {
+ if offline {
+ return nil, fmt.Errorf("readings: offline traditional not yet supported; use lectionary=new offline")
+ }
+ secs, err = tradlit.Load(opts.Date, cfg.TraditionalLang)
+ } else {
+ secs, err = liturgy.Load(liturgy.Options{
+ Date: opts.Date,
+ Refresh: opts.Refresh,
+ Offline: offline,
+ })
+ }
+ if err != nil {
+ return nil, err
+ }
+
+ return filterParts(secs, cfg, opts.All), nil
+}
+
+// filterParts keeps only the gospel when !all (PartID "ewangelia" modern or
+// "evangelium" traditional), otherwise keeps sections cfg.PartShown allows
+// (a section with an empty PartID is always kept). Pure and network-free.
+func filterParts(secs []liturgy.Section, cfg config.Config, all bool) []liturgy.Section {
+ var out []liturgy.Section
+ for _, s := range secs {
+ if !all {
+ if s.PartID == "ewangelia" || s.PartID == "evangelium" {
+ out = append(out, s)
+ }
+ continue
+ }
+ if s.PartID == "" || cfg.PartShown(cfg.Lectionary, s.PartID) {
+ out = append(out, s)
+ }
+ }
+ return out
+}