"},
+ }
+ got := feed("https://kmalloc.org", feedLang(), "/news/", items, 2)
+
+ for _, want := range []string{
+ "kmalloc.org: News",
+ "https://kmalloc.org/news/",
+ "The news & more.",
+ "en",
+ ``,
+ "New <post>",
+ "https://kmalloc.org/news/2026/11/new.html",
+ `https://kmalloc.org/news/2026/11/new.html`,
+ "Sat, 14 Nov 2026 12:00:00 +0100",
+ "Sat, 14 Nov 2026 12:00:00 +0100",
+ `<a href="https://kmalloc.org/people.html">`,
+ } {
+ if !strings.Contains(got, want) {
+ t.Errorf("feed does not contain %q\n%s", want, got)
+ }
+ }
+ if strings.Contains(got, "older.html") {
+ t.Error("feed has a third item but the limit is 2")
+ }
+ if err := xml.Unmarshal([]byte(got), new(any)); err != nil {
+ t.Errorf("feed is not well-formed XML: %v", err)
+ }
+}
+
+// TestFeedWithoutPosts checks that an empty feed is still a valid channel.
+func TestFeedWithoutPosts(t *testing.T) {
+ got := feed("https://kmalloc.org", feedLang(), "/news/", nil, 20)
+ if strings.Contains(got, "lastBuildDate") || strings.Contains(got, "") {
+ t.Errorf("empty feed has dates or items:\n%s", got)
+ }
+ if err := xml.Unmarshal([]byte(got), new(any)); err != nil {
+ t.Errorf("empty feed is not well-formed XML: %v", err)
+ }
+}
diff --git a/internal/build/news.go b/internal/build/news.go
new file mode 100644
index 0000000..a9f6e89
--- /dev/null
+++ b/internal/build/news.go
@@ -0,0 +1,120 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+// Package build assembles a site from its configuration, content, templates
+// and assets, and writes it to a folder.
+package build
+
+import (
+ "fmt"
+ "sort"
+ "strings"
+
+ "git.kmalloc.org/squid/motorino/internal/content"
+ "git.kmalloc.org/squid/motorino/internal/render"
+)
+
+// dateOnly is the layout of the dates shown in lists.
+const dateOnly = "2006-01-02"
+
+// renderedPost is a post together with its body already converted to HTML.
+type renderedPost struct {
+ content.Post
+ // HTML is the body of the post as HTML, placeholders already replaced.
+ HTML string
+}
+
+// newsItem returns the
of a post for a list: the date, the title as a
+// link and, when withDescription is set and there is one, the description. News
+// are written in English, so on any other language the link says so.
+func newsItem(p content.Post, lang string, withDescription bool) string {
+ mark := ""
+ if lang != "en" {
+ mark = ` hreflang="en" lang="en"`
+ }
+ day := p.Date.Format(dateOnly)
+ item := fmt.Sprintf(`
"
+}
+
+// newsList returns the full list of the news as a
, or an empty string
+// when there are no posts.
+func newsList(posts []content.Post, lang string) string {
+ if len(posts) == 0 {
+ return ""
+ }
+ items := make([]string, len(posts))
+ for i, p := range posts {
+ items[i] = newsItem(p, lang, true)
+ }
+ return "
\n" + strings.Join(items, "\n") + "\n
"
+}
+
+// latestNews returns the
items of the first n posts, without the
+// and without descriptions, for the home page.
+func latestNews(posts []content.Post, lang string, n int) string {
+ if n > len(posts) {
+ n = len(posts)
+ }
+ items := make([]string, n)
+ for i := 0; i < n; i++ {
+ items[i] = newsItem(posts[i], lang, false)
+ }
+ return strings.Join(items, "\n")
+}
+
+// categoriesList returns the list of the categories, sorted by name, each with
+// the number of posts, and the categories themselves. With no categories both
+// are empty.
+func categoriesList(posts []content.Post) (string, []content.Category) {
+ counts := map[string]int{}
+ byslug := map[string]content.Category{}
+ for _, p := range posts {
+ for _, c := range p.Categories {
+ counts[c.Slug]++
+ byslug[c.Slug] = c
+ }
+ }
+ if len(byslug) == 0 {
+ return "", nil
+ }
+ cats := make([]content.Category, 0, len(byslug))
+ for _, c := range byslug {
+ cats = append(cats, c)
+ }
+ sort.Slice(cats, func(i, j int) bool {
+ a, b := strings.ToLower(cats[i].Name), strings.ToLower(cats[j].Name)
+ if a != b {
+ return a < b
+ }
+ return cats[i].Name < cats[j].Name
+ })
+ items := make([]string, len(cats))
+ for i, c := range cats {
+ items[i] = fmt.Sprintf(`