- Draft: true and a date in the future keep a post out of the pages, the lists, the categories and the feed. motorino build -drafts (next commit) shows them. - news_language in site.json, and an optional Language key in a post, choose the language of the news pages and of the interface strings they use. The news still exist once, not once per language. - New header keys Mastodon (an https address), Draft and Language; a post knows its reading time and whether its description was written. Refs #9
51 lines
1.7 KiB
Go
51 lines
1.7 KiB
Go
// 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))
|
|
}
|