-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdetailed.go
74 lines (64 loc) · 1.3 KB
/
detailed.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"io"
"log"
"os"
"path"
"text/template"
)
type DetailedPage struct {
Title string
Style *Styles
Post *Post
}
const DETAILED_PAGE_TEMPLATE = `
<html>
<head>
{{ template "styles" .Style }}
<title>{{ .Title }} - {{ .Post.Title }}</title>
</head>
<body>
<a href="/">
<h1 id="header">{{ .Title }}</h1>
</a>
{{ template "post" .Post }}
</body>
</html>
`
func saveDetailedPage(page DetailedPage, conf Config) {
p := path.Join(os.TempDir(), "parellagram", conf.Resources.Posts, page.Post.Filename)
file, err := os.Create(p)
if err != nil {
log.Fatal("Error generating page : ", err)
}
buildDetailedPage(page, file)
}
func saveDetailedPages(conf Config) {
posts := buildPosts(conf.Resources.Posts)
styles := buildStyles(conf.Resources.Styles)
for _, post := range posts {
page := DetailedPage{
Title: conf.Website.Title,
Style: styles,
Post: post,
}
saveDetailedPage(page, conf)
}
}
func buildDetailedPage(page DetailedPage, w io.Writer) {
tmpl := template.New("detailed")
var err error
parse := func(template string) {
if err != nil {
return
}
tmpl, err = tmpl.Parse(template)
}
parse(DETAILED_PAGE_TEMPLATE)
parse(STYLES_TEMPLATE)
parse(POST_TEMPLATE)
if err != nil {
log.Fatal(err)
}
_ = tmpl.Execute(w, page)
}