Home

blog @f4cd5442ea20b11b0e1f33e8a96c7abcc6f84e48 - refs - log -
-
https://git.jolheiser.com/blog.git
My nonexistent blog
blog / blog.go
- raw
 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")
	}
}