aboutsummaryrefslogtreecommitdiff
path: root/internal/calfeed/build.go
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-07-27 21:30:56 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-07-27 21:30:56 +0200
commitbec7c034aca15537900d74a7063d85c0f4deacae (patch)
treebaf4cac4e3a38507b8a0f9de80ac251a5df82908 /internal/calfeed/build.go
parent2901c73fde7ff19e8cdea00f933dc628d11c6ec6 (diff)
downloadlectio-bec7c034aca15537900d74a7063d85c0f4deacae.tar.gz
lectio-bec7c034aca15537900d74a7063d85c0f4deacae.zip
feat(calfeed): shared day builder + reusable reading resolver
Diffstat (limited to 'internal/calfeed/build.go')
-rw-r--r--internal/calfeed/build.go68
1 files changed, 68 insertions, 0 deletions
diff --git a/internal/calfeed/build.go b/internal/calfeed/build.go
new file mode 100644
index 0000000..d3962aa
--- /dev/null
+++ b/internal/calfeed/build.go
@@ -0,0 +1,68 @@
+package calfeed
+
+import (
+ "strings"
+ "time"
+
+ "github.com/lukaszkasprzak/lectio/internal/calendar"
+)
+
+// Build computes the day list from..to inclusive (calendar.Compute per date)
+// and maps it to the wire model. readings is injected -- the caller passes
+// caldata.Readings -- so calfeed never imports internal/caldata.
+func Build(from, to time.Time, uiLang string, sel calendar.Selection, layers []calendar.Layer, readings func(date time.Time, day calendar.LiturgicalDay) []calendar.Reading) []DayView {
+ var days []DayView
+ for d := from; !d.After(to); d = d.AddDate(0, 0, 1) {
+ day := calendar.Compute(d, sel, layers)
+
+ others := make([]CelView, 0, len(day.Others))
+ for _, o := range day.Others {
+ others = append(others, celView(uiLang, o))
+ }
+
+ var rs []ReadingView
+ for _, r := range readings(d, day) {
+ rs = append(rs, ReadingView{Part: r.Part, Citation: r.Citation})
+ }
+
+ days = append(days, DayView{
+ Date: d.Format("2006-01-02"),
+ Season: string(day.Season),
+ Week: day.Week,
+ Weekday: day.Weekday.String(),
+ Colour: string(day.Colour),
+ Observed: celView(uiLang, day.Observed),
+ Others: others,
+ Cycles: Cycles{Sunday: day.SundayCycle, Weekday: day.WeekdayCycle},
+ Readings: rs,
+ })
+ }
+ return days
+}
+
+// celView maps a calendar.Celebration to its wire view.
+func celView(uiLang string, c calendar.Celebration) CelView {
+ return CelView{
+ Slug: c.Slug,
+ Name: celebrationName(uiLang, c),
+ Rank: string(c.Rank),
+ Class: int(c.Class),
+ }
+}
+
+// celebrationName resolves c's name in uiLang, falling back to English, then
+// a humanized slug (with the "ef-" prefix stripped and dashes turned to
+// spaces), then "(feria)" for an unnamed temporal day. Mirrors
+// cli.celebrationName.
+func celebrationName(uiLang string, c calendar.Celebration) string {
+ if n := c.Name[uiLang]; n != "" {
+ return n
+ }
+ if n := c.Name["en"]; n != "" {
+ return n
+ }
+ if c.Slug == "" {
+ return "(feria)"
+ }
+ return strings.ReplaceAll(strings.TrimPrefix(c.Slug, "ef-"), "-", " ")
+}