diff options
Diffstat (limited to 'internal/web/server.go')
| -rw-r--r-- | internal/web/server.go | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/internal/web/server.go b/internal/web/server.go index 7d9dfe5..f02bc12 100644 --- a/internal/web/server.go +++ b/internal/web/server.go @@ -219,6 +219,10 @@ type indexData struct { Display string Mono bool Reading template.HTML + // MonthOpts/YearOpts populate the "pobierz" panel's month-calendar + // download pickers (localised month names + a year window around the + // shown date). + MonthOpts, YearOpts []calOpt // L holds the localised control labels (lectionary/layout/theme/...), // set from i18n.Get(cfg.UILanguage) -- index.html references its // fields (e.g. {{.L.Lectionary}}) instead of hardcoded Polish text. @@ -232,6 +236,13 @@ type versionOpt struct { Checked bool } +// calOpt is one <option> in the pobierz panel's month or year picker. +type calOpt struct { + Val int + Label string + Sel bool +} + type themeOpt struct { Name string Selected bool @@ -276,6 +287,23 @@ func indexHandler(cfg config.Config) http.HandlerFunc { themeOpts = append(themeOpts, themeOpt{Name: name, Selected: name == theme}) } + // Month/year pickers for the "pobierz" panel's month-calendar download. + // Selected from the shown date; the year list is a small window around + // it so the shown year is always present and pre-selected. + labels := i18n.Get(cfg.UILanguage) + selYear, selMonth := 0, 0 + if t, err := time.Parse("2006-01-02", date); err == nil { + selYear, selMonth = t.Year(), int(t.Month()) + } + monthOpts := make([]calOpt, 0, 12) + for i, name := range labels.Months { + monthOpts = append(monthOpts, calOpt{Val: i + 1, Label: name, Sel: i+1 == selMonth}) + } + yearOpts := make([]calOpt, 0, 6) + for y := selYear - 2; y <= selYear+3; y++ { + yearOpts = append(yearOpts, calOpt{Val: y, Label: strconv.Itoa(y), Sel: y == selYear}) + } + data := indexData{ Date: date, PrevDate: shiftDate(date, -1), @@ -288,7 +316,9 @@ func indexHandler(cfg config.Config) http.HandlerFunc { Display: display, Mono: queryBool(r, "mono", cfg.WebMono), Reading: reading, - L: i18n.Get(cfg.UILanguage), + MonthOpts: monthOpts, + YearOpts: yearOpts, + L: labels, Lang: cfg.UILanguage, } |
