`)
}
// TestBuildErrorsOnMissingTemplate checks that a missing layout template is named.
diff --git a/internal/build/feed.go b/internal/build/feed.go
index d9adb7c..b9a1aeb 100644
--- a/internal/build/feed.go
+++ b/internal/build/feed.go
@@ -15,10 +15,16 @@ import (
// href="/people.html", but not one that is relative to the protocol (href="//host/x").
var siteRelative = regexp.MustCompile(`\b(href|src)="/([^/])`)
+// cdata wraps text in a CDATA section; the end marker inside the text is split
+// over two sections, so it cannot close the first one.
+func cdata(text string) string {
+ return "", "]]]]>") + "]]>"
+}
+
// feed returns the RSS 2.0 feed of the latest limit posts, which must be sorted
-// newest first. Each item carries the full text with absolute links. The
-// channel is described by the language l, and newsURL is the address of the
-// news page, such as "/news/".
+// newest first. Each item has the description as a plain summary and the full
+// text, with absolute links, in content:encoded. The channel is described by
+// the language l, and newsURL is the address of the news page, such as "/news/".
func feed(base string, l site.Lang, newsURL string, posts []renderedPost, limit int) string {
if limit < len(posts) {
posts = posts[:limit]
@@ -32,7 +38,16 @@ func feed(base string, l site.Lang, newsURL string, posts []renderedPost, limit
items.WriteString("" + link + "\n")
items.WriteString(`` + link + "\n")
items.WriteString("" + p.Date.Format(time.RFC1123Z) + "\n")
- items.WriteString("" + render.Escape(text) + "\n")
+ if p.Description != "" {
+ items.WriteString("" + render.Escape(p.Description) + "\n")
+ }
+ if p.Author != "" {
+ items.WriteString("" + render.Escape(p.Author) + "\n")
+ }
+ for _, c := range p.Categories {
+ items.WriteString("" + render.Escape(c.Name) + "\n")
+ }
+ items.WriteString("" + cdata(text) + "\n")
items.WriteString("\n")
}
built := ""
@@ -41,7 +56,7 @@ func feed(base string, l site.Lang, newsURL string, posts []renderedPost, limit
}
url := base + newsURL
return `
-
+kmalloc.org: ` + render.Escape(l.Nav["news"]) + `
` + url + `
diff --git a/internal/build/feed_test.go b/internal/build/feed_test.go
index bf3b932..78c27a1 100644
--- a/internal/build/feed_test.go
+++ b/internal/build/feed_test.go
@@ -18,7 +18,7 @@ func feedLang() site.Lang {
// TestFeedItems checks the channel, the item fields, the limit and the dates.
func TestFeedItems(t *testing.T) {
items := []renderedPost{
- {Post: testPost("new", "2026-11-14", "New ", ""), HTML: `
"},
}
@@ -35,7 +35,11 @@ func TestFeedItems(t *testing.T) {
`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">`,
+ `xmlns:content="http://purl.org/rss/1.0/modules/content/"`,
+ "A summary & more.",
+ `See people.]]>`,
+ "FLUG",
+ "Linux Day",
} {
if !strings.Contains(got, want) {
t.Errorf("feed does not contain %q\n%s", want, got)
@@ -49,6 +53,34 @@ func TestFeedItems(t *testing.T) {
}
}
+// TestFeedCarriesTheFullTextAsContent checks that the text is in content:encoded and the
+// description stays a plain summary, and that the end marker of a CDATA section in a text
+// does not close it.
+func TestFeedCarriesTheFullTextAsContent(t *testing.T) {
+ post := testPost("a", "2026-11-14", "A", "Short.")
+ post.Author = "Matteo Bini"
+ items := []renderedPost{{Post: post, HTML: "
" {
+ t.Errorf("content:encoded = %+v, want the text back as written", parsed.Channel.Items)
+ }
+}
+
// TestFeedLeavesProtocolRelativeLinks checks that "//host/x" is not given the site address.
func TestFeedLeavesProtocolRelativeLinks(t *testing.T) {
items := []renderedPost{{Post: testPost("a", "2026-11-14", "A", ""), HTML: `p`}}