forked from avelino/awesome-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scripts.go
51 lines (45 loc) · 1009 Bytes
/
scripts.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
package main
import (
"bytes"
"html/template"
"io/ioutil"
"os"
"github.com/PuerkitoBio/goquery"
"github.com/avelino/awesome-go/pkg/markdown"
)
func readme() []byte {
input, err := os.ReadFile("./README.md")
if err != nil {
panic(err)
}
html, err := markdown.ConvertMarkdownToHTML(input)
if err != nil {
panic(err)
}
return html
}
func startQuery() *goquery.Document {
buf := bytes.NewBuffer(readme())
query, err := goquery.NewDocumentFromReader(buf)
if err != nil {
panic(err)
}
return query
}
type content struct {
Body template.HTML
}
// GenerateHTML generate site html (index.html) from markdown file
func GenerateHTML() (err error) {
// options
readmePath := "./README.md"
tplPath := "tmpl/tmpl.html"
idxPath := "tmpl/index.html"
input, _ := ioutil.ReadFile(readmePath)
body, _ := markdown.ConvertMarkdownToHTML(input)
c := &content{Body: template.HTML(body)}
t := template.Must(template.ParseFiles(tplPath))
f, err := os.Create(idxPath)
t.Execute(f, c)
return
}