-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
75 lines (61 loc) · 2.11 KB
/
Copy pathmain.go
File metadata and controls
75 lines (61 loc) · 2.11 KB
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
75
package main
import (
"fmt"
"github.com/beyondchan28/beyondchan28.github.io/blog"
"github.com/beyondchan28/beyondchan28.github.io/xdparser"
"strings"
)
func addPage(pg *[]xdparser.PageData, filename string) {
blogDir := "./static/xdfiles/"
page := xdparser.PageData{}
page.ReadXDFileNative(blogDir + filename + ".xd")
*pg = append(*pg, page)
}
func main() {
// NOTE: Generate index HTML
index := xdparser.PageData{}
index.ReadXDFileNative("./static/xdfiles/index.xd")
title, date, body, footer := index.GenerateHTML()
indexContent := fmt.Sprintf(blog.Main, title, date, body, footer)
blog.WriteHTML(indexContent, "./index.html")
//NOTE: Prepare Blog page
var pages []xdparser.PageData
addPage(&pages, "page")
addPage(&pages, "page2")
addPage(&pages, "page3")
addPage(&pages, "page4")
addPage(&pages, "page5")
addPage(&pages, "page6")
for idx, pg := range pages {
fileName := fmt.Sprintf("./templates/page%d.html", idx)
title, date, body, footer := pg.GenerateHTML()
content := fmt.Sprintf(blog.Main, title, date, body, footer)
blog.WriteHTML(content, fileName)
}
//NOTE: Create blogPage list
var blogPageList strings.Builder
for idx, pg := range pages {
pageId := idx
var titleId int
var dateId int
for _, pageMap := range pg.PageMapArray {
if v, ok := pageMap[xdparser.TITLE]; ok {
titleId = v[0]
} else if v, ok := pageMap[xdparser.DATE]; ok {
dateId = v[0]
}
}
link := fmt.Sprintf(`<a href="./page%d.html">%s</a>`, pageId, pg.Texts[titleId])
blogTitle := fmt.Sprintf(`<div class="blog-title">%s</div>`, link)
blogDate := fmt.Sprintf(`<div class="published-date">%s</div>`, pg.Texts[dateId])
blogItem := fmt.Sprintf(`<li class="blog-item">%s%s</li>`, blogTitle, blogDate)
blogPageList.WriteString(blogItem)
}
blogContent := fmt.Sprintf(blog.BlogList, blogPageList.String())
blog.WriteHTML(blogContent, "./templates/blog.html")
gamesPage := xdparser.PageData{}
gamesPage.ReadXDFileNative("./static/xdfiles/games.xd")
t, d, b, f := gamesPage.GenerateHTML()
gamesContent := fmt.Sprintf(blog.Main, t, d, b, f)
blog.WriteHTML(gamesContent, "./templates/games.html")
}