1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
diff --git a/blog.go b/blog.go
index 644353a354057efe605a8a87576faa2ecb9dc9c9..5e4bdef0e3fbb23e7ccc2bb4d612d74887d864e0 100644
--- a/blog.go
+++ b/blog.go
@@ -105,17 +105,22 @@ }
// Index renders the blog index to w
func (b *Blog) Index(w io.Writer) error {
+ byCat := make(map[string][]Article)
+ for _, article := range b.Articles {
+ byCat[article.Category] = append(byCat[article.Category], article)
+ }
return b.indexTemplate.Execute(w, map[string]any{
- "articles": b.Articles,
- "author": b.Author,
+ "Articles": b.Articles,
+ "ArticlesByCategory": byCat,
+ "Author": b.Author,
})
}
// Article renders an article to w
func (b *Blog) Article(w io.Writer, a Article) error {
return b.articleTemplate.Execute(w, map[string]any{
- "article": a,
- "author": b.Author,
+ "Article": a,
+ "Author": b.Author,
})
}
|