aboutsummaryrefslogtreecommitdiff
path: root/internal/web/server.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/web/server.go')
-rw-r--r--internal/web/server.go84
1 files changed, 16 insertions, 68 deletions
diff --git a/internal/web/server.go b/internal/web/server.go
index c7e645d..76a5d3b 100644
--- a/internal/web/server.go
+++ b/internal/web/server.go
@@ -1,12 +1,11 @@
// This file wires the package's render helpers (RenderReadings, Themes,
// themeCSS, the embedded static/templates FS) into an HTTP server: the full
-// page (GET /), the HTMX reading-pane partial (GET /readings), a passage
-// lookup partial (GET /lookup), a theme stylesheet endpoint (GET
-// /theme.css) and the embedded static assets (GET /static/...).
+// page (GET /), the HTMX reading-pane partial (GET /readings), a theme
+// stylesheet endpoint (GET /theme.css) and the embedded static assets (GET
+// /static/...).
package web
import (
- "bytes"
"fmt"
"html/template"
"io"
@@ -19,7 +18,6 @@ import (
"strings"
"time"
- "github.com/lukaszkasprzak/lectio/internal/bible"
"github.com/lukaszkasprzak/lectio/internal/config"
"github.com/lukaszkasprzak/lectio/internal/liturgy"
"github.com/lukaszkasprzak/lectio/internal/readings"
@@ -39,7 +37,6 @@ func NewServer(cfg config.Config) http.Handler {
mux.HandleFunc("GET /{$}", indexHandler(cfg))
mux.HandleFunc("GET /readings", readingsHandler(cfg))
- mux.HandleFunc("GET /lookup", lookupHandler(cfg))
mux.HandleFunc("GET /theme.css", themeCSSHandler(cfg))
staticSub, err := fs.Sub(staticFS, "static")
@@ -76,12 +73,14 @@ func shiftDate(date string, days int) string {
}
// requestVersions returns the versions requested via one or more repeated
-// ?v= query params, falling back to cfg.Versions when none were given.
+// ?v= query params, falling back to a single cfg.DefaultVersion (not the
+// full cfg.Versions set) when none were given, so a plain visit checks
+// exactly one version box.
func requestVersions(cfg config.Config, r *http.Request) []string {
if vs, ok := r.URL.Query()["v"]; ok && len(vs) > 0 {
return vs
}
- return append([]string(nil), cfg.Versions...)
+ return []string{cfg.DefaultVersion}
}
// queryBool reads a truthy/falsy query param ("1"/"true"/"on"/"yes" vs.
@@ -138,15 +137,20 @@ func resolveQuery(cfg config.Config, r *http.Request) (date, lectionary string,
}
// loadSections runs the readings router for one request: date/lectionary
-// override cfg, all controls part filtering, and (when cfg.Offline)
-// versions is swapped via render.OfflineVersions before being handed back
-// to the caller for rendering -- so the caller's column labels always match
-// what was actually loadable.
+// override cfg, all controls part filtering, and versions is swapped via
+// render.OfflineVersions -- when cfg.Offline (any lectionary needs the
+// 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) {
cfg.Lectionary = lectionary
if cfg.Offline {
versions = render.OfflineVersions(versions)
}
+ if lectionary == "traditional" {
+ versions = render.OfflineVersions(versions)
+ }
secs, err := readings.Load(cfg, readings.Options{
Date: date,
Offline: cfg.Offline,
@@ -165,8 +169,6 @@ type indexData struct {
Theme string
Display string
Mono bool
- Ref string
- Lookup template.HTML
Reading template.HTML
}
@@ -209,12 +211,6 @@ func indexHandler(cfg config.Config) http.HandlerFunc {
themeOpts = append(themeOpts, themeOpt{Name: name, Selected: name == theme})
}
- ref := r.URL.Query().Get("ref") // echoed into the lookup box on a shared/bookmarked link
- var lookup template.HTML
- if ref != "" {
- lookup = renderLookup(ref, versions)
- }
-
data := indexData{
Date: date,
PrevDate: shiftDate(date, -1),
@@ -226,8 +222,6 @@ func indexHandler(cfg config.Config) http.HandlerFunc {
Theme: theme,
Display: display,
Mono: queryBool(r, "mono", cfg.WebMono),
- Ref: ref,
- Lookup: lookup,
Reading: reading,
}
@@ -266,52 +260,6 @@ func renderOrError(secs []liturgy.Section, versions []string, lectionary, displa
return RenderReadings(secs, versions, lectionary, display)
}
-// lookupColumn is what templates/lookup.html ranges over: one per requested
-// version.
-type lookupColumn struct {
- Version string
- Verses []bible.Verse
- Missing []string
-}
-
-// renderLookup renders the passage-lookup fragment for ref (looked up as-is
-// -- already English/kjv-style, e.g. "J 20:1" -- against each of versions
-// via bible.Lookup directly; no Polish->English conversion, that only
-// applies to a section's own citation via render.GatherVersion, not a
-// free-typed lookup) against each requested version. Shared by lookupHandler
-// (the HTMX partial) and indexHandler (so a bookmarked/shared "/?ref=..."
-// link shows the same result instead of an empty pane). ref is trimmed of
-// surrounding whitespace here so both routes treat a whitespace-only ref
-// identically; an empty (or now-empty) ref renders nothing, matching
-// lookupHandler's previous no-op behavior.
-func renderLookup(ref string, versions []string) template.HTML {
- ref = strings.TrimSpace(ref)
- if ref == "" {
- return ""
- }
- cols := make([]lookupColumn, 0, len(versions))
- for _, v := range versions {
- verses, missing := bible.Lookup(v, ref)
- cols = append(cols, lookupColumn{Version: v, Verses: verses, Missing: missing})
- }
-
- var buf bytes.Buffer
- if err := tmpl.ExecuteTemplate(&buf, "lookup.html", cols); err != nil {
- return template.HTML(`<p class="error">` + template.HTMLEscapeString(err.Error()) + `</p>`)
- }
- return template.HTML(buf.String())
-}
-
-// lookupHandler serves the passage-lookup fragment via renderLookup (see
-// its doc comment for the lookup semantics).
-func lookupHandler(cfg config.Config) http.HandlerFunc {
- return func(w http.ResponseWriter, r *http.Request) {
- ref := r.URL.Query().Get("ref") // renderLookup trims whitespace
- w.Header().Set("Content-Type", "text/html; charset=utf-8")
- io.WriteString(w, string(renderLookup(ref, requestVersions(cfg, r))))
- }
-}
-
// themeCSSHandler serves one theme's stylesheet: the requested name, or
// (unknown/invalid) cfg.WebTheme, or (that also unknown) the built-in
// default -- so an unrecognized ?name= degrades to a working theme instead