feat(news): blog list with pages, and an archive by year and month
- {{news_blog}} lists the posts as entries (title, long date, categories,
description, a read more link) 10 to a page; the other pages are written under
the index, at page/2/, page/3/ and so on, with a pager.
- Archive pages for every year and month that has posts, at /news/2026/ and
/news/2026/11/, when templates/archive.html exists, and a {{news_archive}} block.
Refs #9
This commit is contained in:
parent
bf50b2e1c2
commit
4a501d77b3
5 changed files with 411 additions and 4 deletions
243
internal/build/blog.go
Normal file
243
internal/build/blog.go
Normal file
|
|
@ -0,0 +1,243 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
package build
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"git.kmalloc.org/squid/motorino/internal/content"
|
||||
"git.kmalloc.org/squid/motorino/internal/render"
|
||||
)
|
||||
|
||||
// newsPerPage is how many posts one page of the blog list has.
|
||||
const newsPerPage = 10
|
||||
|
||||
// pageCount returns how many pages n posts make: at least one.
|
||||
func pageCount(n int) int {
|
||||
if n <= newsPerPage {
|
||||
return 1
|
||||
}
|
||||
return (n + newsPerPage - 1) / newsPerPage
|
||||
}
|
||||
|
||||
// pagePath returns the address of page n of an index: the index itself for the
|
||||
// first page, then base + "page/2/", "page/3/" and so on. base ends with "/".
|
||||
func pagePath(base string, n int) string {
|
||||
if n <= 1 {
|
||||
return base
|
||||
}
|
||||
return base + "page/" + strconv.Itoa(n) + "/"
|
||||
}
|
||||
|
||||
// pageLabel is "Page 2 of 3" in the language lang, from the string pager_page.
|
||||
func (b *builder) pageLabel(lang string, n, total int) (string, error) {
|
||||
text := b.langs[lang].Strings["pager_page"]
|
||||
if text == "" {
|
||||
return "", fmt.Errorf("lang/%s.json: the language has no pager_page string, which the pages of the blog list need", lang)
|
||||
}
|
||||
return strings.NewReplacer("{n}", strconv.Itoa(n), "{total}", strconv.Itoa(total)).Replace(text), nil
|
||||
}
|
||||
|
||||
// blogEntry returns one entry of the blog list: the title as a link, the date
|
||||
// and the categories, the description as a preview and a link to read more.
|
||||
// lang is the language of the page; a post in another language is marked.
|
||||
func (b *builder) blogEntry(p content.Post, lang string) (string, error) {
|
||||
l := b.langs[lang]
|
||||
more := l.Strings["read_more"]
|
||||
if more == "" {
|
||||
return "", fmt.Errorf("lang/%s.json: the language has no read_more string, which the blog list needs", lang)
|
||||
}
|
||||
mark := ""
|
||||
if p.Language != "" && p.Language != lang {
|
||||
mark = fmt.Sprintf(` hreflang="%s" lang="%s"`, p.Language, p.Language)
|
||||
}
|
||||
meta := fmt.Sprintf(`<time datetime="%s">%s</time>`, p.Date.Format(dateOnly), render.Escape(longDate(p.Date, l)))
|
||||
if links := categoryLinks(p); links != "" {
|
||||
meta += " · " + links
|
||||
}
|
||||
var out strings.Builder
|
||||
out.WriteString("<article>\n")
|
||||
fmt.Fprintf(&out, "<h2><a href=\"%s\"%s>%s</a></h2>\n", p.Path, mark, render.Escape(p.Title))
|
||||
fmt.Fprintf(&out, "<p class=\"meta\">%s</p>\n", meta)
|
||||
if p.Description != "" {
|
||||
fmt.Fprintf(&out, "<p>%s</p>\n", render.Escape(p.Description))
|
||||
}
|
||||
fmt.Fprintf(&out, "<p><a href=\"%s\" aria-label=\"%s: %s\"%s>%s</a></p>\n", p.Path, render.EscapeAttr(more), render.EscapeAttr(p.Title), mark, render.Escape(more))
|
||||
out.WriteString("</article>")
|
||||
return out.String(), nil
|
||||
}
|
||||
|
||||
// newsBlog returns the page n of the blog list of the language lang, with the
|
||||
// pager when the list has more than one page. A site without posts gets the
|
||||
// news_empty text.
|
||||
func (b *builder) newsBlog(lang string, n int, ctx map[string]string) (string, error) {
|
||||
if len(b.posts) == 0 {
|
||||
return "<p>\n" + ctx["news_empty"] + "\n</p>", nil
|
||||
}
|
||||
total := pageCount(len(b.posts))
|
||||
if n < 1 || n > total {
|
||||
n = 1
|
||||
}
|
||||
end := n * newsPerPage
|
||||
if end > len(b.posts) {
|
||||
end = len(b.posts)
|
||||
}
|
||||
entries := make([]string, 0, newsPerPage)
|
||||
for _, p := range b.posts[(n-1)*newsPerPage : end] {
|
||||
entry, err := b.blogEntry(p, lang)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
entries = append(entries, entry)
|
||||
}
|
||||
html := strings.Join(entries, "\n")
|
||||
if total == 1 {
|
||||
return html, nil
|
||||
}
|
||||
pager, err := b.pager(lang, n, total)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return html + "\n" + pager, nil
|
||||
}
|
||||
|
||||
// pager returns the navigation between the pages of the blog list.
|
||||
func (b *builder) pager(lang string, n, total int) (string, error) {
|
||||
l := b.langs[lang]
|
||||
label, newer, older := l.Strings["pager_label"], l.Strings["pager_newer"], l.Strings["pager_older"]
|
||||
if label == "" || newer == "" || older == "" {
|
||||
return "", fmt.Errorf("lang/%s.json: the language lacks pager_label, pager_newer or pager_older, which the pages of the blog list need", lang)
|
||||
}
|
||||
page, err := b.pageLabel(lang, n, total)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
var parts []string
|
||||
if n > 1 {
|
||||
parts = append(parts, fmt.Sprintf(`<a href="%s" rel="prev">%s</a>`, pagePath(b.newsPath, n-1), render.Escape(newer)))
|
||||
}
|
||||
parts = append(parts, render.Escape(page))
|
||||
if n < total {
|
||||
parts = append(parts, fmt.Sprintf(`<a href="%s" rel="next">%s</a>`, pagePath(b.newsPath, n+1), render.Escape(older)))
|
||||
}
|
||||
return fmt.Sprintf("<nav aria-label=\"%s\">\n<p>\n%s\n</p>\n</nav>", render.EscapeAttr(label), strings.Join(parts, "\n·\n")), nil
|
||||
}
|
||||
|
||||
// archiveMonth is the posts of one month; archiveYear the posts of one year.
|
||||
type (
|
||||
archiveMonth struct {
|
||||
year, month int
|
||||
posts []content.Post
|
||||
}
|
||||
archiveYear struct {
|
||||
year int
|
||||
posts []content.Post
|
||||
months []archiveMonth
|
||||
}
|
||||
)
|
||||
|
||||
// groupArchive groups posts, newest first, by year and by month, as written in
|
||||
// their dates. The years and the months are newest first too.
|
||||
func groupArchive(posts []content.Post) []archiveYear {
|
||||
var years []archiveYear
|
||||
for _, p := range posts {
|
||||
y, m := p.Date.Year(), int(p.Date.Month())
|
||||
if len(years) == 0 || years[len(years)-1].year != y {
|
||||
years = append(years, archiveYear{year: y})
|
||||
}
|
||||
year := &years[len(years)-1]
|
||||
year.posts = append(year.posts, p)
|
||||
if len(year.months) == 0 || year.months[len(year.months)-1].month != m {
|
||||
year.months = append(year.months, archiveMonth{year: y, month: m})
|
||||
}
|
||||
month := &year.months[len(year.months)-1]
|
||||
month.posts = append(month.posts, p)
|
||||
}
|
||||
return years
|
||||
}
|
||||
|
||||
// yearPath and monthPath are the addresses of an archive year and month.
|
||||
func (b *builder) yearPath(year int) string { return fmt.Sprintf("%s%04d/", b.newsPath, year) }
|
||||
func (b *builder) monthPath(year, month int) string {
|
||||
return fmt.Sprintf("%s%04d/%02d/", b.newsPath, year, month)
|
||||
}
|
||||
|
||||
// hasArchive reports whether the site has the template of an archive page.
|
||||
func (b *builder) hasArchive() bool {
|
||||
_, ok := b.templates["archive"]
|
||||
return ok
|
||||
}
|
||||
|
||||
// monthList returns the list of the months of a year, each with its posts.
|
||||
func (b *builder) monthList(y archiveYear, lang string) string {
|
||||
items := make([]string, len(y.months))
|
||||
for i, m := range y.months {
|
||||
items[i] = fmt.Sprintf(`<li><a href="%s">%s</a> (%d)</li>`, b.monthPath(m.year, m.month), render.Escape(monthYear(m.year, m.month, b.langs[lang])), len(m.posts))
|
||||
}
|
||||
return "<ul>\n" + strings.Join(items, "\n") + "\n</ul>"
|
||||
}
|
||||
|
||||
// newsArchive returns the nested list of the years and the months that have
|
||||
// posts, or the news_empty text when there are none. It needs the archive pages.
|
||||
func (b *builder) newsArchive(lang string, ctx map[string]string) (string, error) {
|
||||
if _, err := b.template("archive"); err != nil {
|
||||
return "", fmt.Errorf("the {{news_archive}} block needs the archive pages: %w", err)
|
||||
}
|
||||
years := groupArchive(b.posts)
|
||||
if len(years) == 0 {
|
||||
return "<p>\n" + ctx["news_empty"] + "\n</p>", nil
|
||||
}
|
||||
items := make([]string, len(years))
|
||||
for i, y := range years {
|
||||
items[i] = fmt.Sprintf("<li><a href=\"%s\">%d</a> (%d)\n%s</li>", b.yearPath(y.year), y.year, len(y.posts), b.monthList(y, lang))
|
||||
}
|
||||
return "<ul>\n" + strings.Join(items, "\n") + "\n</ul>", nil
|
||||
}
|
||||
|
||||
// renderArchives writes the page of every year and every month that has posts,
|
||||
// when the site has templates/archive.html.
|
||||
func (b *builder) renderArchives() error {
|
||||
if !b.hasArchive() {
|
||||
return nil
|
||||
}
|
||||
tmpl, err := b.template("archive")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
lang := b.newsLang
|
||||
l := b.langs[lang]
|
||||
page := func(path, name, nav string, posts []content.Post, source string) error {
|
||||
d := document{
|
||||
lang: lang, nav: "news", lead: "news", path: path, title: name, prefixed: true,
|
||||
description: l.Strings["archive_h"] + ": " + name, source: source,
|
||||
}
|
||||
ctx := b.documentContext(d)
|
||||
ctx["archive_name"] = render.Escape(name)
|
||||
ctx["archive_nav"] = nav
|
||||
ctx["archive_posts"] = newsList(posts, lang)
|
||||
body, err := render.Substitute("templates/archive.html", tmpl, ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return b.frame(d, ctx, body)
|
||||
}
|
||||
for _, y := range groupArchive(b.posts) {
|
||||
year := strconv.Itoa(y.year)
|
||||
if err := page(b.yearPath(y.year), year, b.monthList(y, lang), y.posts, "the archive of "+year); err != nil {
|
||||
return err
|
||||
}
|
||||
up := ""
|
||||
if text := l.Strings["archive_up"]; text != "" {
|
||||
up = fmt.Sprintf("<p><a href=\"%s\">%s %s</a></p>", b.yearPath(y.year), render.Escape(text), year)
|
||||
}
|
||||
for _, m := range y.months {
|
||||
name := monthYear(m.year, m.month, l)
|
||||
if err := page(b.monthPath(m.year, m.month), name, up, m.posts, "the archive of "+name); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
@ -299,3 +299,125 @@ func TestPostOpenGraphArticle(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// blogIndex is a news index that uses the blog list and the archive.
|
||||
const blogIndex = "Title: News\nID: news\nDescription: About News.\n-\n# News\n\n{{news_blog}}\n\n## Archive\n\n{{news_archive}}\n"
|
||||
|
||||
// archiveTemplate is the page of a year or a month of the archive.
|
||||
const archiveTemplate = "<h1>{{archive_h}}: {{archive_name}}</h1>\n\n{{archive_nav}}\n\n{{archive_posts}}\n"
|
||||
|
||||
// manyPosts adds n posts, dated one per day from 2026-10-01, to the files.
|
||||
func manyPosts(files map[string]string, n int) map[string]string {
|
||||
for i := 1; i <= n; i++ {
|
||||
day := "2026-10-" + string(rune('0'+i/10)) + string(rune('0'+i%10))
|
||||
name := "p" + string(rune('0'+i/10)) + string(rune('0'+i%10))
|
||||
files["news/"+name+".md"] = "Title: Post " + name[1:] + "\nDate: " + day + "T12:00:00+0100\nCategories: Many\n-\nText of " + name + ".\n"
|
||||
}
|
||||
return files
|
||||
}
|
||||
|
||||
// TestNewsBlogEntries checks one entry of the blog list and the absence of a pager for a short list.
|
||||
func TestNewsBlogEntries(t *testing.T) {
|
||||
out, err := buildWith(t, blogSite(map[string]string{"content/en/news/index.md": blogIndex, "templates/archive.html": archiveTemplate}), nil)
|
||||
if err != nil {
|
||||
t.Fatalf("Build() error = %v", err)
|
||||
}
|
||||
index := readOut(t, out, "news/index.html")
|
||||
mustContain(t, "news index", index,
|
||||
"<article>\n<h2><a href=\"/news/2026/11/shop.html\">A shop</a></h2>",
|
||||
`<p class="meta"><time datetime="2026-11-14">14 November 2026</time> · <a href="/news/category/flug.html">FLUG</a></p>`,
|
||||
"<p>About the shop.</p>",
|
||||
`<p><a href="/news/2026/11/shop.html" aria-label="Read more: A shop">Read more</a></p>`,
|
||||
)
|
||||
if got := strings.Count(index, "<article>"); got != 3 {
|
||||
t.Errorf("the index has %d entries, want 3", got)
|
||||
}
|
||||
if strings.Contains(index, "News pages") {
|
||||
t.Error("a list that fits one page has a pager")
|
||||
}
|
||||
}
|
||||
|
||||
// TestNewsBlogPagination checks the pages of a long list.
|
||||
func TestNewsBlogPagination(t *testing.T) {
|
||||
files := blogSite(map[string]string{"content/en/news/index.md": blogIndex, "templates/archive.html": archiveTemplate})
|
||||
out, err := buildWith(t, manyPosts(files, 22), nil)
|
||||
if err != nil {
|
||||
t.Fatalf("Build() error = %v", err)
|
||||
}
|
||||
first := readOut(t, out, "news/index.html")
|
||||
mustContain(t, "page 1", first, `<nav aria-label="News pages">`, `Page 1 of 3`, `<a href="/news/page/2/" rel="next">Older news</a>`)
|
||||
if strings.Contains(first, `rel="prev"`) || strings.Count(first, "<article>") != 10 || !strings.Contains(first, "Post 15") || strings.Contains(first, "Post 14") {
|
||||
t.Errorf("page 1 is wrong:\n%s", first)
|
||||
}
|
||||
second := readOut(t, out, "news/page/2/index.html")
|
||||
mustContain(t, "page 2", second, `Page 2 of 3`, `<a href="/news/" rel="prev">Newer news</a>`, `<a href="/news/page/3/" rel="next">Older news</a>`,
|
||||
"<title>News, Page 2 of 3</title>", "Post 14", "Post 05")
|
||||
if strings.Count(second, "<article>") != 10 || strings.Contains(second, "Post 15") || strings.Contains(second, "Post 04") {
|
||||
t.Errorf("page 2 is wrong:\n%s", second)
|
||||
}
|
||||
third := readOut(t, out, "news/page/3/index.html")
|
||||
mustContain(t, "page 3", third, `Page 3 of 3`, `<a href="/news/page/2/" rel="prev">Newer news</a>`, "GNU/Linux Day 2026")
|
||||
if strings.Contains(third, `rel="next"`) || strings.Count(third, "<article>") != 5 {
|
||||
t.Errorf("page 3 is wrong:\n%s", third)
|
||||
}
|
||||
if exists(t, out, "news/page/4/index.html") || exists(t, out, "news/page/1/index.html") {
|
||||
t.Error("there is a page 4 or a page 1 under /news/page/")
|
||||
}
|
||||
robots := readOut(t, out, "robots.txt")
|
||||
mustContain(t, "robots.txt", robots, "/news/page/2/")
|
||||
}
|
||||
|
||||
// TestNewsBlogNeedsItsStrings checks that a blog list without read_more is an error.
|
||||
func TestNewsBlogNeedsItsStrings(t *testing.T) {
|
||||
files := blogSite(map[string]string{"content/en/news/index.md": blogIndex, "lang/en.json": strings.Replace(blogLangEn, `"read_more": "Read more", `, "", 1), "templates/archive.html": archiveTemplate})
|
||||
_, err := buildWith(t, files, nil)
|
||||
if err == nil || !strings.Contains(err.Error(), "read_more") {
|
||||
t.Errorf("error = %v, want one that names read_more", err)
|
||||
}
|
||||
}
|
||||
|
||||
// TestNewsBlogOnlyOnAnIndex checks that the blog list needs an index page.
|
||||
func TestNewsBlogOnlyOnAnIndex(t *testing.T) {
|
||||
files := blogSite(map[string]string{"content/en/news/index.md": blogIndex, "content/en/extra.md": page("extra", "Extra", "", "{{news_blog}}\n"), "templates/archive.html": archiveTemplate})
|
||||
_, err := buildWith(t, files, nil)
|
||||
if err == nil || !strings.Contains(err.Error(), "index") {
|
||||
t.Errorf("error = %v, want one about an index page", err)
|
||||
}
|
||||
}
|
||||
|
||||
// TestArchivePages checks the pages of a year and of a month, and the block.
|
||||
func TestArchivePages(t *testing.T) {
|
||||
out, err := buildWith(t, blogSite(map[string]string{"content/en/news/index.md": blogIndex, "templates/archive.html": archiveTemplate}), nil)
|
||||
if err != nil {
|
||||
t.Fatalf("Build() error = %v", err)
|
||||
}
|
||||
mustContain(t, "news index", readOut(t, out, "news/index.html"),
|
||||
`<li><a href="/news/2026/">2026</a> (3)`,
|
||||
`<li><a href="/news/2026/11/">November 2026</a> (2)</li>`,
|
||||
`<li><a href="/news/2026/09/">September 2026</a> (1)</li>`)
|
||||
year := readOut(t, out, "news/2026/index.html")
|
||||
mustContain(t, "year", year, "<h1>Archive: 2026</h1>", `<a href="/news/2026/11/">November 2026</a> (2)`, "A shop", "Status page", "GNU/Linux Day 2026")
|
||||
month := readOut(t, out, "news/2026/11/index.html")
|
||||
mustContain(t, "month", month, "<h1>Archive: November 2026</h1>", `<a href="/news/2026/">Archive of the year 2026</a>`, "A shop", "Status page")
|
||||
if strings.Contains(month, "GNU/Linux Day 2026") {
|
||||
t.Error("the month of November lists a post of September")
|
||||
}
|
||||
if exists(t, out, "news/2026/12/index.html") || exists(t, out, "news/2025/index.html") {
|
||||
t.Error("an archive page exists for a month or a year without posts")
|
||||
}
|
||||
}
|
||||
|
||||
// TestNoArchiveWithoutTemplate checks that the archive is opt in, and that its block then is an error.
|
||||
func TestNoArchiveWithoutTemplate(t *testing.T) {
|
||||
out, err := buildWith(t, blogSite(map[string]string{"content/en/news/index.md": strings.Replace(blogIndex, "{{news_archive}}", "", 1)}), nil)
|
||||
if err != nil {
|
||||
t.Fatalf("Build() error = %v", err)
|
||||
}
|
||||
if exists(t, out, "news/2026/index.html") {
|
||||
t.Error("an archive page is built without templates/archive.html")
|
||||
}
|
||||
_, err = buildWith(t, blogSite(map[string]string{"content/en/news/index.md": blogIndex}), nil)
|
||||
if err == nil || !strings.Contains(err.Error(), "archive") {
|
||||
t.Errorf("error = %v, want one that names the archive template", err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -114,6 +114,9 @@ func Build(opts Options) (Result, error) {
|
|||
if err := b.renderCategories(); err != nil {
|
||||
return Result{}, err
|
||||
}
|
||||
if err := b.renderArchives(); err != nil {
|
||||
return Result{}, err
|
||||
}
|
||||
if err := b.renderFeed(); err != nil {
|
||||
return Result{}, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import (
|
|||
|
||||
// blockNames are the placeholders that expand to generated HTML. Until they
|
||||
// are expanded they stand for themselves, so a page can hold them.
|
||||
var blockNames = []string{"news_list", "latest_news", "categories_list"}
|
||||
var blockNames = []string{"news_list", "latest_news", "categories_list", "news_blog", "news_archive"}
|
||||
|
||||
// document describes one output page for the shared page frame.
|
||||
type document struct {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ package build
|
|||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"git.kmalloc.org/squid/motorino/internal/content"
|
||||
|
|
@ -22,18 +23,51 @@ func (b *builder) renderPages() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// renderPage converts the body of a page to HTML, expands the generated lists,
|
||||
// puts it in its layout and in the shared frame.
|
||||
// blogBlock matches a paragraph that holds the blog list placeholder.
|
||||
var blogBlock = regexp.MustCompile(`(?m)^\{\{news_blog\}\}\s*$`)
|
||||
|
||||
// renderPage renders a page. A page with the blog list is rendered once for
|
||||
// every page of the list: the first at its own address, the others under it, at
|
||||
// page/2/, page/3/ and so on.
|
||||
func (b *builder) renderPage(p content.Page) error {
|
||||
total := 1
|
||||
if blogBlock.MatchString(p.Body) {
|
||||
if !strings.HasSuffix(p.Path, "/") {
|
||||
return fmt.Errorf("%s: {{news_blog}} must be on an index page (an index.md), so that its pages have addresses under it", p.Source)
|
||||
}
|
||||
total = pageCount(len(b.posts))
|
||||
}
|
||||
for n := 1; n <= total; n++ {
|
||||
if err := b.renderPageNumber(p, n, total); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// renderPageNumber converts the body of a page to HTML, expands the generated
|
||||
// lists, puts it in its layout and in the shared frame. n is the number of the
|
||||
// page of the blog list, out of total; both are 1 for any other page.
|
||||
func (b *builder) renderPageNumber(p content.Page, n, total int) error {
|
||||
d := document{
|
||||
lang: p.Lang, id: p.ID, lead: "back", path: p.Path, title: p.Title,
|
||||
lang: p.Lang, id: p.ID, lead: "back", path: pagePath(p.Path, n), title: p.Title,
|
||||
description: p.Description, switches: p.Switch, source: p.Source,
|
||||
}
|
||||
d.nav = p.ID
|
||||
if p.ID == "home" {
|
||||
d.lead = "home"
|
||||
}
|
||||
if n > 1 {
|
||||
label, err := b.pageLabel(p.Lang, n, total)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
d.id, d.switches = "", nil
|
||||
d.title = p.Title + ", " + label
|
||||
d.source = fmt.Sprintf("%s (page %d of the list)", p.Source, n)
|
||||
}
|
||||
ctx := b.documentContext(d)
|
||||
ctx["news_page_n"] = strconv.Itoa(n)
|
||||
if p.ManifestoVersion != "" {
|
||||
ctx["manifesto_version"] = render.Escape(p.ManifestoVersion)
|
||||
}
|
||||
|
|
@ -133,6 +167,11 @@ func (b *builder) block(name, lang string, ctx map[string]string) (string, error
|
|||
return list, nil
|
||||
}
|
||||
return "<p>\n" + ctx["news_empty"] + "\n</p>", nil
|
||||
case "news_blog":
|
||||
n, _ := strconv.Atoi(ctx["news_page_n"])
|
||||
return b.newsBlog(lang, n, ctx)
|
||||
case "news_archive":
|
||||
return b.newsArchive(lang, ctx)
|
||||
case "latest_news":
|
||||
if len(b.posts) == 0 {
|
||||
return "", nil
|
||||
|
|
|
|||
Loading…
Reference in a new issue