2020-09-24 21:21:00 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
2021-12-22 13:12:40 +00:00
|
|
|
"os"
|
|
|
|
"text/template"
|
2020-09-24 21:21:00 +00:00
|
|
|
|
|
|
|
"github.com/PuerkitoBio/goquery"
|
2021-12-22 13:12:40 +00:00
|
|
|
"github.com/gomarkdown/markdown"
|
|
|
|
"github.com/gomarkdown/markdown/parser"
|
2020-09-24 21:21:00 +00:00
|
|
|
"github.com/russross/blackfriday"
|
|
|
|
)
|
|
|
|
|
|
|
|
func readme() []byte {
|
|
|
|
input, err := ioutil.ReadFile("./README.md")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
html := fmt.Sprintf("<body>%s</body>", blackfriday.MarkdownCommon(input))
|
|
|
|
htmlByteArray := []byte(html)
|
|
|
|
return htmlByteArray
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
Body string
|
|
|
|
}
|
|
|
|
|
|
|
|
func GenerateHTML() (err error) {
|
|
|
|
// options
|
|
|
|
readmePath := "./README.md"
|
|
|
|
tplPath := "tmpl/tmpl.html"
|
|
|
|
idxPath := "tmpl/index.html"
|
|
|
|
input, _ := ioutil.ReadFile(readmePath)
|
|
|
|
extensions := parser.CommonExtensions | parser.AutoHeadingIDs | parser.LaxHTMLBlocks
|
|
|
|
parser := parser.NewWithExtensions(extensions)
|
|
|
|
|
|
|
|
body := string(markdown.ToHTML(input, parser, nil))
|
|
|
|
// body := string(gfm.Markdown(input))
|
|
|
|
c := &content{Body: body}
|
|
|
|
t := template.Must(template.ParseFiles(tplPath))
|
|
|
|
f, err := os.Create(idxPath)
|
|
|
|
t.Execute(f, c)
|
|
|
|
return
|
|
|
|
}
|