-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
readme.go
63 lines (53 loc) · 1.55 KB
/
readme.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
package internal
import (
"fmt"
"io/ioutil"
"log"
"strconv"
)
func convertIssueToList(i issue, config conf) string {
return fmt.Sprintf("\n- [%s](http://%s)\n", i.Title, config.Host+"/"+formatFileNmae(i))
}
func convertBlogrollList(bs []blogroll) string {
blogroll := ""
for _, b := range bs {
blogroll += fmt.Sprintf("\n- [%s](%s)", b.Name, b.URL)
}
return blogroll
}
func groupIssues(issues []issue) [][]issue {
if len(issues) == 0 {
log.Fatal("must have one issue")
}
var is [][]issue
var currentIssues []issue
var currentTime = strconv.Itoa(issues[0].CreatedAt.Year()) + "-" + strconv.Itoa(int(issues[0].CreatedAt.Month()))
for _, i := range issues {
t := strconv.Itoa(i.CreatedAt.Year()) + "-" + strconv.Itoa(int(i.CreatedAt.Month()))
if t == currentTime {
currentIssues = append(currentIssues, i)
} else {
currentTime = t
is = append(is, currentIssues)
currentIssues = []issue{i}
}
}
is = append(is, currentIssues)
return is
}
func (g *generateBlog) saveReadme(issues []issue) {
readme := fmt.Sprintf("%s\n> created by issue\n\n", g.config.Name)
groupIss := groupIssues(issues)
for _, iss := range groupIss {
readme += fmt.Sprintf("\n### %s", strconv.Itoa(iss[0].CreatedAt.Year())+"-"+strconv.Itoa(int(iss[0].CreatedAt.Month())))
for _, i := range iss {
readme += convertIssueToList(i, g.config)
}
}
blogroll := convertBlogrollList(g.config.Blogrolls)
readme, err := parseToReadme(readme, blogroll, g.token, g.config)
if err != nil {
log.Fatal(err)
}
ioutil.WriteFile("index.html", []byte(readme), 0644)
}