// SPDX-License-Identifier: GPL-3.0-or-later package build import ( "fmt" "strconv" "strings" "time" "git.kmalloc.org/squid/motorino/internal/site" ) // longDate writes a date for a reader, in the language l, from the strings // date_long (a layout with {d}, {month} and {y}) and month_01 to month_12. The // day, the month and the year are those of the date as written, not converted // to another time zone. A language without the layout, or without the name of // the month, gets the ISO date. func longDate(date time.Time, l site.Lang) string { layout := l.Strings["date_long"] month := l.Strings[fmt.Sprintf("month_%02d", int(date.Month()))] if layout == "" || month == "" { return date.Format(dateOnly) } return strings.NewReplacer( "{d}", strconv.Itoa(date.Day()), "{month}", month, "{y}", strconv.Itoa(date.Year()), ).Replace(layout) } // monthYear is the label of an archive month in the language l, from the // strings date_month_year (a layout with {month} and {y}) and month_01 to // month_12; without them it is the year and the month, "2026-11". func monthYear(year, month int, l site.Lang) string { layout := l.Strings["date_month_year"] name := l.Strings[fmt.Sprintf("month_%02d", month)] if layout == "" || name == "" { return fmt.Sprintf("%04d-%02d", year, month) } return strings.NewReplacer("{month}", name, "{y}", strconv.Itoa(year)).Replace(layout) } // readingText is the reading time of a post in the language l, from the string // reading_time (a sentence with {n}); without the string it is empty and no // reading time is shown. func readingText(minutes int, l site.Lang) string { layout := l.Strings["reading_time"] if layout == "" { return "" } return strings.ReplaceAll(layout, "{n}", strconv.Itoa(minutes)) }