summaryrefslogtreecommitdiff
path: root/internal/web
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-07-24 10:32:28 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-07-24 10:32:28 +0200
commitc9f3bf46f0de09edb796e35f3dcff349febf75c9 (patch)
treec1a0b98b484e4da557c1ab205dfff0d92ce8ac36 /internal/web
parenta865374755480a4aef2a6156afccdf08a91422ea (diff)
downloadlectio-c9f3bf46f0de09edb796e35f3dcff349febf75c9.tar.gz
lectio-c9f3bf46f0de09edb796e35f3dcff349febf75c9.zip
dayinfo: show feast/day name + colour (modern niedziela + traditional missalemeum) in cli/tui/web; v0.5.0
Diffstat (limited to 'internal/web')
-rw-r--r--internal/web/render.go39
-rw-r--r--internal/web/render_test.go56
-rw-r--r--internal/web/server.go23
-rw-r--r--internal/web/server_test.go9
-rw-r--r--internal/web/static/base.css17
5 files changed, 118 insertions, 26 deletions
diff --git a/internal/web/render.go b/internal/web/render.go
index 1afee1c..9e6280c 100644
--- a/internal/web/render.go
+++ b/internal/web/render.go
@@ -98,16 +98,45 @@ type ilLineView struct {
// spans so theme CSS can restyle them; verse/paragraph text is escaped by
// html/template. lang localises the version-column labels and each section
// heading's part-label word (render.LocalizeHeading, brief §3b); the
-// citation/verse text is never touched.
-func RenderReadings(secs []liturgy.Section, versions []string, lectionary, display, lang string) template.HTML {
+// citation/verse text is never touched. dayInfo is rendered once, ahead of
+// every layout's own sections, as the day's celebration header (see
+// renderDayInfo) -- never translated (source-language, like the readings/
+// citations), and simply omitted when the source carried none.
+func RenderReadings(secs []liturgy.Section, versions []string, lectionary, display, lang string, dayInfo liturgy.DayInfo) template.HTML {
+ var body template.HTML
switch display {
case "vertical":
- return renderTemplate("readings-vertical.html", buildColumnViews(secs, versions, lectionary, lang))
+ body = renderTemplate("readings-vertical.html", buildColumnViews(secs, versions, lectionary, lang))
case "interlinear":
- return renderTemplate("readings-interlinear.html", buildInterlinearViews(secs, versions, lectionary, lang))
+ body = renderTemplate("readings-interlinear.html", buildInterlinearViews(secs, versions, lectionary, lang))
default:
- return renderTemplate("readings.html", buildColumnViews(secs, versions, lectionary, lang))
+ body = renderTemplate("readings.html", buildColumnViews(secs, versions, lectionary, lang))
}
+ return renderDayInfo(dayInfo) + body
+}
+
+// renderDayInfo builds the "<p class="dayinfo">" header RenderReadings
+// prepends to the reading pane: the celebration Name as its heading-role
+// span, the temporal Season (if any) as its citation-role span. Reusing
+// those two role classes (rather than inventing new ones) means every
+// existing theme restyles it identically without a new CSS rule -- see
+// base.css/docs/THEMES.md. Returns "" (the header is simply omitted, never
+// an error) when the source yielded no DayInfo (info.Name == "").
+func renderDayInfo(info liturgy.DayInfo) template.HTML {
+ if info.Name == "" {
+ return ""
+ }
+ var b strings.Builder
+ b.WriteString(`<p class="dayinfo"><span class="heading">`)
+ b.WriteString(template.HTMLEscapeString(info.Name))
+ b.WriteString(`</span>`)
+ if info.Season != "" {
+ b.WriteString(` <span class="citation">`)
+ b.WriteString(template.HTMLEscapeString(info.Season))
+ b.WriteString(`</span>`)
+ }
+ b.WriteString(`</p>`)
+ return template.HTML(b.String())
}
// renderTemplate executes the named embedded template with data, degrading
diff --git a/internal/web/render_test.go b/internal/web/render_test.go
index b7f5b1e..de3c7c1 100644
--- a/internal/web/render_test.go
+++ b/internal/web/render_test.go
@@ -11,12 +11,52 @@ import (
func TestRenderReadings(t *testing.T) {
secs := []liturgy.Section{{Heading: "Ewangelia (J 20, 1. 11-18)", PartID: "ewangelia"}}
- html := string(RenderReadings(secs, []string{"wuj"}, "new", "horizontal", "pl"))
+ html := string(RenderReadings(secs, []string{"wuj"}, "new", "horizontal", "pl", liturgy.DayInfo{}))
if !strings.Contains(html, "Ewangelia") || !strings.Contains(html, "class=") {
t.Errorf("reading pane missing heading/classes: %q", html[:min(200, len(html))])
}
}
+// TestRenderReadingsDayInfoHeader checks RenderReadings prepends a
+// "<p class="dayinfo">" header carrying the celebration Name (heading role)
+// and Season (citation role, muted) ahead of the reading sections, and that
+// it reuses the existing role classes rather than inventing new ones.
+func TestRenderReadingsDayInfoHeader(t *testing.T) {
+ secs := []liturgy.Section{{Heading: "Ewangelia (J 20, 1. 11-18)", PartID: "ewangelia"}}
+ info := liturgy.DayInfo{Name: "Święto św. Marii Magdaleny", Colour: "white"}
+ html := string(RenderReadings(secs, []string{"wuj"}, "new", "horizontal", "pl", info))
+ if !strings.Contains(html, `class="dayinfo"`) {
+ t.Errorf("missing dayinfo header: %q", html[:min(300, len(html))])
+ }
+ if !strings.Contains(html, "Święto św. Marii Magdaleny") {
+ t.Errorf("dayinfo header missing the day name: %q", html[:min(300, len(html))])
+ }
+ if i := strings.Index(html, `class="dayinfo"`); i > strings.Index(html, "reading-section") && strings.Index(html, "reading-section") != -1 {
+ t.Errorf("dayinfo header should come before the reading sections: %q", html[:min(400, len(html))])
+ }
+}
+
+// TestRenderReadingsDayInfoSeason checks the Season (traditional lectionary
+// only) renders as a muted citation-role span alongside Name.
+func TestRenderReadingsDayInfoSeason(t *testing.T) {
+ secs := []liturgy.Section{{Heading: "Gospel", PartID: "evangelium"}}
+ info := liturgy.DayInfo{Name: "St. Mary Magdalene", Season: "Feria IV after VIII Sunday after Pentecost", Colour: "white"}
+ html := string(RenderReadings(secs, []string{"wuj"}, "traditional", "horizontal", "en", info))
+ if !strings.Contains(html, "Feria IV after VIII Sunday after Pentecost") {
+ t.Errorf("dayinfo header missing Season: %q", html[:min(400, len(html))])
+ }
+}
+
+// TestRenderReadingsNoDayInfoHeaderWhenEmpty checks the header is entirely
+// omitted (never an empty/error stub) when the source yielded no DayInfo.
+func TestRenderReadingsNoDayInfoHeaderWhenEmpty(t *testing.T) {
+ secs := []liturgy.Section{{Heading: "Ewangelia (J 20, 1. 11-18)", PartID: "ewangelia"}}
+ html := string(RenderReadings(secs, []string{"wuj"}, "new", "horizontal", "pl", liturgy.DayInfo{}))
+ if strings.Contains(html, `class="dayinfo"`) {
+ t.Errorf("dayinfo header should be omitted when Name is empty: %q", html)
+ }
+}
+
func TestBuiltinThemes(t *testing.T) {
t.Setenv("XDG_CONFIG_HOME", t.TempDir()) // no user themes
for _, name := range []string{
@@ -45,7 +85,7 @@ func TestRenderReadingsEscapesScriptText(t *testing.T) {
PartID: "pierwsze_czytanie",
Paragraphs: [][]string{{"<script>alert(1)</script>"}},
}}
- html := string(RenderReadings(secs, []string{"bt"}, "new", "horizontal", "pl"))
+ html := string(RenderReadings(secs, []string{"bt"}, "new", "horizontal", "pl", liturgy.DayInfo{}))
if strings.Contains(html, "<script>alert(1)</script>") {
t.Errorf("raw <script> leaked into rendered output: %q", html)
}
@@ -56,7 +96,7 @@ func TestRenderReadingsEscapesScriptText(t *testing.T) {
func TestRenderReadingsVertical(t *testing.T) {
secs := []liturgy.Section{{Heading: "Ewangelia (J 20, 1. 11-18)", PartID: "ewangelia"}}
- html := string(RenderReadings(secs, []string{"wuj", "vul"}, "new", "vertical", "pl"))
+ html := string(RenderReadings(secs, []string{"wuj", "vul"}, "new", "vertical", "pl", liturgy.DayInfo{}))
if !strings.Contains(html, "display-vertical") {
t.Errorf("vertical output missing display-vertical container: %q", html[:min(300, len(html))])
}
@@ -70,7 +110,7 @@ func TestRenderReadingsVertical(t *testing.T) {
func TestRenderReadingsInterlinear(t *testing.T) {
secs := []liturgy.Section{{Heading: "Ewangelia (J 20, 1. 11-18)", PartID: "ewangelia"}}
- html := string(RenderReadings(secs, []string{"wuj", "vul"}, "new", "interlinear", "pl"))
+ html := string(RenderReadings(secs, []string{"wuj", "vul"}, "new", "interlinear", "pl", liturgy.DayInfo{}))
if !strings.Contains(html, "ilverse") {
t.Errorf("interlinear output missing ilverse: %q", html[:min(300, len(html))])
}
@@ -91,7 +131,7 @@ func TestRenderReadingsInterlinear(t *testing.T) {
func TestRenderReadingsInterlinearExcludesBT(t *testing.T) {
secs := []liturgy.Section{{Heading: "Ewangelia (J 20, 1. 11-18)", PartID: "ewangelia"}}
- html := string(RenderReadings(secs, []string{"bt", "vul"}, "new", "interlinear", "pl"))
+ html := string(RenderReadings(secs, []string{"bt", "vul"}, "new", "interlinear", "pl", liturgy.DayInfo{}))
if strings.Contains(html, "Biblia Tysiąclecia (niedziela.pl)") {
t.Errorf("interlinear output should substitute wuj for bt, not carry bt's label: %q", html[:min(300, len(html))])
}
@@ -102,7 +142,7 @@ func TestRenderReadingsInterlinearExcludesBT(t *testing.T) {
func TestRenderReadingsInterlinearNoVersifiedNote(t *testing.T) {
secs := []liturgy.Section{{Heading: "Bez odwołania", PartID: "ewangelia"}}
- html := string(RenderReadings(secs, []string{"wuj"}, "new", "interlinear", "pl"))
+ html := string(RenderReadings(secs, []string{"wuj"}, "new", "interlinear", "pl", liturgy.DayInfo{}))
if strings.Contains(html, "ilverse") {
t.Errorf("expected no ilverse blocks when nothing resolves: %q", html)
}
@@ -115,7 +155,7 @@ func TestRenderReadingsInterlinearNoVersifiedNote(t *testing.T) {
// "no verses to align" note (finding §1) follows lang, not always Polish.
func TestRenderReadingsInterlinearNoVersifiedNoteLang(t *testing.T) {
secs := []liturgy.Section{{Heading: "Bez odwołania", PartID: "ewangelia"}}
- html := string(RenderReadings(secs, []string{"wuj"}, "new", "interlinear", "en"))
+ html := string(RenderReadings(secs, []string{"wuj"}, "new", "interlinear", "en", liturgy.DayInfo{}))
if !strings.Contains(html, "(no verses to align)") {
t.Errorf("en no-verses note missing/wrong: %q", html)
}
@@ -130,7 +170,7 @@ func TestRenderReadingsInterlinearNoVersifiedNoteLang(t *testing.T) {
// citation stays exactly as scraped.
func TestRenderReadingsLocalizesEN(t *testing.T) {
secs := []liturgy.Section{{Heading: "Ewangelia (J 20, 1. 11-18)", PartID: "ewangelia"}}
- html := string(RenderReadings(secs, []string{"vul"}, "new", "horizontal", "en"))
+ html := string(RenderReadings(secs, []string{"vul"}, "new", "horizontal", "en", liturgy.DayInfo{}))
if !strings.Contains(html, "Gospel (J 20, 1. 11-18)") {
t.Errorf("en output missing localised heading: %q", html[:min(300, len(html))])
}
diff --git a/internal/web/server.go b/internal/web/server.go
index 110dae7..d8b451a 100644
--- a/internal/web/server.go
+++ b/internal/web/server.go
@@ -156,16 +156,17 @@ func resolveQuery(cfg config.Config, r *http.Request) (date, lectionary string,
// network-free set), or when lectionary is "traditional" (pl is the
// niedziela.pl modern scrape, meaningless for missalemeum) -- before being
// handed back to the caller for rendering, so the caller's column labels
-// always match what was actually loadable.
-func loadSections(cfg config.Config, lectionary, date string, all bool, versions []string) ([]liturgy.Section, []string, error) {
+// always match what was actually loadable. dayInfo is the day's celebration
+// identity (see liturgy.DayInfo), zero when the source carried none.
+func loadSections(cfg config.Config, lectionary, date string, all bool, versions []string) (secs []liturgy.Section, dayInfo liturgy.DayInfo, effVersions []string, err error) {
cfg.Lectionary = lectionary
- versions = render.EffectiveVersions(versions, lectionary, cfg.Offline)
- secs, err := readings.Load(cfg, readings.Options{
+ effVersions = render.EffectiveVersions(versions, lectionary, cfg.Offline)
+ secs, dayInfo, err = readings.Load(cfg, readings.Options{
Date: date,
Offline: cfg.Offline,
All: all,
})
- return secs, versions, err
+ return secs, dayInfo, effVersions, err
}
// indexData is what templates/index.html ranges/branches over.
@@ -208,8 +209,8 @@ func indexHandler(cfg config.Config) http.HandlerFunc {
theme = cfg.WebTheme
}
- secs, loadVersions, err := loadSections(cfg, lectionary, date, all, versions)
- reading := renderOrError(secs, loadVersions, lectionary, display, cfg.UILanguage, err)
+ secs, dayInfo, loadVersions, err := loadSections(cfg, lectionary, date, all, versions)
+ reading := renderOrError(secs, loadVersions, lectionary, display, cfg.UILanguage, dayInfo, err)
// Check the boxes for the versions actually rendered (loadVersions),
// not the raw request: traditional/offline substitute pl->wuj, so the
@@ -258,8 +259,8 @@ func readingsHandler(cfg config.Config) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
date, lectionary, all, versions, display := resolveQuery(cfg, r)
- secs, loadVersions, err := loadSections(cfg, lectionary, date, all, versions)
- reading := renderOrError(secs, loadVersions, lectionary, display, cfg.UILanguage, err)
+ secs, dayInfo, loadVersions, err := loadSections(cfg, lectionary, date, all, versions)
+ reading := renderOrError(secs, loadVersions, lectionary, display, cfg.UILanguage, dayInfo, err)
w.Header().Set("Content-Type", "text/html; charset=utf-8")
io.WriteString(w, string(reading))
@@ -271,14 +272,14 @@ func readingsHandler(cfg config.Config) http.HandlerFunc {
// paragraph, localised via lang -- readings.Load errors are expected in
// normal operation (an unpublished date, no network while online, ...) so
// the pane should show them, not 500.
-func renderOrError(secs []liturgy.Section, versions []string, lectionary, display, lang string, err error) template.HTML {
+func renderOrError(secs []liturgy.Section, versions []string, lectionary, display, lang string, dayInfo liturgy.DayInfo, err error) template.HTML {
if err != nil {
return template.HTML(`<p class="error">` + template.HTMLEscapeString(err.Error()) + `</p>`)
}
if len(secs) == 0 {
return template.HTML(`<p class="error">` + template.HTMLEscapeString(i18n.Get(lang).NoReadingsDay) + `</p>`)
}
- return RenderReadings(secs, versions, lectionary, display, lang)
+ return RenderReadings(secs, versions, lectionary, display, lang, dayInfo)
}
// themeCSSHandler serves one theme's stylesheet: the requested name, or
diff --git a/internal/web/server_test.go b/internal/web/server_test.go
index 00da039..809ee59 100644
--- a/internal/web/server_test.go
+++ b/internal/web/server_test.go
@@ -50,6 +50,11 @@ func TestServer(t *testing.T) {
if !strings.Contains(body, `id="theme"`) {
t.Errorf("body missing theme <link>")
}
+ // Name is source-language (Polish), never translated, even
+ // though the surrounding chrome is English -- see RenderReadings.
+ if !strings.Contains(body, `class="dayinfo"`) || !strings.Contains(body, "Święto św. Marii Magdaleny") {
+ t.Errorf("body missing day-info header: %q", body)
+ }
})
t.Run("readings partial", func(t *testing.T) {
@@ -230,7 +235,7 @@ func TestServer(t *testing.T) {
// TestRenderOrErrorNoSectionsLang checks the "no readings at all for this
// day" fragment (finding §1) follows lang instead of always being Polish.
func TestRenderOrErrorNoSectionsLang(t *testing.T) {
- html := string(renderOrError(nil, nil, "new", "horizontal", "en", nil))
+ html := string(renderOrError(nil, nil, "new", "horizontal", "en", liturgy.DayInfo{}, nil))
if !strings.Contains(html, "no readings for this day") {
t.Errorf("en renderOrError(no secs) = %q, want it to contain %q", html, "no readings for this day")
}
@@ -238,7 +243,7 @@ func TestRenderOrErrorNoSectionsLang(t *testing.T) {
t.Errorf("en renderOrError(no secs) should not carry Polish wording: %q", html)
}
- html = string(renderOrError(nil, nil, "new", "horizontal", "pl", nil))
+ html = string(renderOrError(nil, nil, "new", "horizontal", "pl", liturgy.DayInfo{}, nil))
if !strings.Contains(html, "brak czytań na ten dzień") {
t.Errorf("pl renderOrError(no secs) = %q, want it to contain %q", html, "brak czytań na ten dzień")
}
diff --git a/internal/web/static/base.css b/internal/web/static/base.css
index b5ce9a5..1e30b1d 100644
--- a/internal/web/static/base.css
+++ b/internal/web/static/base.css
@@ -94,6 +94,23 @@ body.mono {
color: var(--fg);
}
+/* Day-info header (feast/day name + optional temporal season):
+ * RenderReadings prepends this once, ahead of every layout's own sections.
+ * It reuses the .heading/.citation role classes (rather than a bespoke
+ * rule) so every theme restyles it the same way it already restyles a
+ * reading section's own heading/citation -- no new colour rule needed. */
+.dayinfo {
+ margin: 0 0 var(--space-3);
+}
+
+.dayinfo .heading {
+ margin: 0 0 0.25rem;
+}
+
+.dayinfo .citation {
+ margin: 0;
+}
+
/* Reading pane */
.reading-section {
margin: 0 0 var(--space-4);