From 378926240f34759116b19e078d2b2504965f5329 Mon Sep 17 00:00:00 2001 From: Lukasz Kasprzak Date: Fri, 24 Jul 2026 16:56:07 +0200 Subject: export: month calendar PDF (A4 landscape, Monday-first grid, feast name + gospel ref + liturgical colour per day); cli --calendar YYYY-MM; web /calendar + link; readings.GospelCitation; v0.23.0 --- internal/cli/cli.go | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) (limited to 'internal/cli/cli.go') diff --git a/internal/cli/cli.go b/internal/cli/cli.go index 88d3a30..24d1fec 100644 --- a/internal/cli/cli.go +++ b/internal/cli/cli.go @@ -52,7 +52,8 @@ Flags: --rand-ch print a random chapter and exit --md export the readings as Markdown (to --out or stdout) --pdf export the readings as PDF (to --out or stdout) - --out FILE write --md/--pdf output to FILE + --out FILE write --md/--pdf/--calendar output to FILE + --calendar YYYY-MM export the month as a printable A4 PDF calendar -v, --version print the version and exit -h, --help this help @@ -112,7 +113,7 @@ func Run(args []string, stdin io.Reader, stdout, stderr io.Writer) int { var all, raw, refresh, offline, update, clean, pagerFlag, noPager, citation, week bool var randV, randCh bool var expMD, expPDF bool - var output string + var output, calendar string var bibleVer, compareList, lectionary, lang string var width int var list bool @@ -159,6 +160,7 @@ func Run(args []string, stdin io.Reader, stdout, stderr io.Writer) int { fs.BoolVar(&expPDF, "pdf", false, "export the readings as PDF") fs.StringVar(&output, "out", "", "write --md/--pdf output to FILE (default: stdout)") fs.StringVar(&output, "output", "", "write --md/--pdf output to FILE (default: stdout)") + fs.StringVar(&calendar, "calendar", "", "export a month (YYYY-MM) as a printable A4 PDF calendar") if err := fs.Parse(rest); err != nil { return 2 @@ -230,6 +232,9 @@ func Run(args []string, stdin io.Reader, stdout, stderr io.Writer) int { } return runExport(cfg, date, ver, effAll, refresh, expPDF, output, stdout, stderr) } + if calendar != "" { + return runCalendar(cfg, calendar, output, stdout, stderr) + } effWidth := width if effWidth == 0 { effWidth = cfg.Width @@ -394,6 +399,45 @@ func runExport(cfg config.Config, date, version string, all, refresh, asPDF bool return 0 } +// runCalendar handles --calendar YYYY-MM: gather each day's celebration name + +// gospel reference + liturgical colour for the month (gospel-only loads, offline +// -aware) and render a printable A4 PDF calendar to --out FILE (or stdout). +func runCalendar(cfg config.Config, ym, output string, stdout, stderr io.Writer) int { + t, err := time.Parse("2006-01", ym) + if err != nil { + fmt.Fprintf(stderr, "lectio: invalid --calendar %q (want YYYY-MM)\n", ym) + return 2 + } + year, month := t.Year(), int(t.Month()) + first := time.Date(year, time.Month(month), 1, 0, 0, 0, 0, time.UTC) + + var days []export.CalendarDay + for d := first; int(d.Month()) == month; d = d.AddDate(0, 0, 1) { + cd := export.CalendarDay{Day: d.Day()} + if secs, info, lerr := readings.Load(cfg, readings.Options{Date: d.Format("2006-01-02"), Offline: cfg.Offline, All: false}); lerr == nil { + cd.Name = info.Name + cd.Colour = info.Colour + cd.Citation = readings.GospelCitation(secs) + } + days = append(days, cd) + } + + data, err := export.CalendarPDF(year, month, days, cfg.Lectionary, cfg.UILanguage) + if err != nil { + fmt.Fprintln(stderr, "lectio:", err) + return 1 + } + if output != "" { + if err := os.WriteFile(output, data, 0o644); err != nil { + fmt.Fprintln(stderr, "lectio:", err) + return 1 + } + return 0 + } + _, _ = stdout.Write(data) + return 0 +} + // runCitation handles --citation: fetch the day's gospel (gospel-only) and // print just its scripture reference in the configured sigla dialect (see // dialectCitation), for scripts/cron/prompt use. Honors the resolved cfg -- cgit v1.3