2020-09-24 21:21:00 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2022-08-30 21:52:53 +00:00
|
|
|
"html/template"
|
2020-09-24 21:21:00 +00:00
|
|
|
"io/ioutil"
|
2021-12-22 13:12:40 +00:00
|
|
|
"os"
|
2020-09-24 21:21:00 +00:00
|
|
|
|
|
|
|
"github.com/PuerkitoBio/goquery"
|
2022-08-30 21:52:53 +00:00
|
|
|
"github.com/avelino/awesome-go/pkg/markdown"
|
2020-09-24 21:21:00 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func readme() []byte {
|
2022-08-30 21:52:53 +00:00
|
|
|
input, err := os.ReadFile("./README.md")
|
2020-09-24 21:21:00 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2022-08-30 21:52:53 +00:00
|
|
|
html, err := markdown.ConvertMarkdownToHTML(input)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return html
|
2020-09-24 21:21:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func startQuery() *goquery.Document {
|
|
|
|
buf := bytes.NewBuffer(readme())
|
|
|
|
query, err := goquery.NewDocumentFromReader(buf)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return query
|
|
|
|
}
|
2021-12-22 13:12:40 +00:00
|
|
|
|
|
|
|
type content struct {
|
2022-08-30 21:52:53 +00:00
|
|
|
Body template.HTML
|
2021-12-22 13:12:40 +00:00
|
|
|
}
|
|
|
|
|
2021-12-27 09:55:03 +00:00
|
|
|
// GenerateHTML generate site html (index.html) from markdown file
|
2021-12-22 13:12:40 +00:00
|
|
|
func GenerateHTML() (err error) {
|
|
|
|
// options
|
|
|
|
readmePath := "./README.md"
|
|
|
|
tplPath := "tmpl/tmpl.html"
|
|
|
|
idxPath := "tmpl/index.html"
|
|
|
|
input, _ := ioutil.ReadFile(readmePath)
|
2022-08-30 21:52:53 +00:00
|
|
|
body, _ := markdown.ConvertMarkdownToHTML(input)
|
|
|
|
c := &content{Body: template.HTML(body)}
|
2021-12-22 13:12:40 +00:00
|
|
|
t := template.Must(template.ParseFiles(tplPath))
|
|
|
|
f, err := os.Create(idxPath)
|
|
|
|
t.Execute(f, c)
|
|
|
|
return
|
|
|
|
}
|