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
32
33
34
35
36
37
38
|
package blog
import (
"errors"
"fmt"
"html/template"
"time"
)
// Blog is a collection of [Article]
type Blog struct {
indexTemplate *template.Template
articleTemplate *template.Template
Articles []Article
}
// Article is a blog post/article
type Article struct {
Title string
Subtitle string
Summary string
Time time.Time
Authors []string
Tags []string
}
func NewBlog(dir string) (*Blog, error) {
tmpl, err := parseTemplates()
if err != nil {
return nil, fmt.Errorf("could not parse templates in %q: %w", dir, err)
}
if tmpl.Lookup("index") == nil {
return nil, errors.New("`index` template is required but was not found")
}
if tmpl.Lookup("article") == nil {
return nil, errors.New("`article` template is required but was not found")
}
}
|