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

63 lines
1.1 KiB
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
2023-02-03 20:39:51 -05:00
func GenerateHTML(srcFilename, outFilename string) error {
input, err := ioutil.ReadFile(srcFilename)
if err != nil {
return err
}
body, err := markdown.ConvertMarkdownToHTML(input)
if err != nil {
return err
}
2022-08-30 17:52:53 -04:00
c := &content{Body: template.HTML(body)}
t := template.Must(template.ParseFiles(tplPath))
2023-02-03 20:39:51 -05:00
f, err := os.Create(outFilename)
if err != nil {
return err
}
if err := t.Execute(f, c); err != nil {
return err
}
return nil
}