1
0
Fork 0
mirror of https://github.com/avelino/awesome-go.git synced 2024-11-13 11:14:37 -05:00
go/scripts.go

52 lines
1,009 B
Go
Raw Normal View History

package main
import (
"bytes"
2022-08-30 17:52:53 -04:00
"html/template"
"io/ioutil"
"os"
"github.com/PuerkitoBio/goquery"
2022-08-30 17:52:53 -04:00
"github.com/avelino/awesome-go/pkg/markdown"
)
func readme() []byte {
2022-08-30 17:52:53 -04:00
input, err := os.ReadFile("./README.md")
if err != nil {
panic(err)
}
2022-08-30 17:52:53 -04:00
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 {
2022-08-30 17:52:53 -04:00
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)
2022-08-30 17:52:53 -04:00
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
}