-
Notifications
You must be signed in to change notification settings - Fork 1
/
post.go
45 lines (40 loc) · 816 Bytes
/
post.go
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
39
40
41
42
43
44
45
package blawg
import (
"fmt"
"html/template"
"time"
)
// A Post for the blog
type Post struct {
Body template.HTML
Title template.HTML
Date time.Time
TitleText string
Metadata
}
// The Metadata of a Post
type Metadata struct {
Title string `yaml:"title"`
Layout string `yaml:"layout"`
Date string `yaml:"date"`
Categories []string `yaml:"tags"`
Published bool `yaml:"published"`
Description string `yaml:"description"`
}
// Path of a post
func (p *Post) Path() string {
postPathTitle := urlSafeFileName(p.TitleText)
postPath := fmt.Sprintf(
"%d/%d/%d/%s/",
p.Date.Year(),
p.Date.Month(),
p.Date.Day(),
postPathTitle,
)
return postPath
}
// A PostPage is the page with a post on
type PostPage struct {
Post *Post
PostList *Posts
}