mirror of
https://github.com/avelino/awesome-go.git
synced 2024-11-07 16:33:40 +00:00
pass all html's through goquery
This commit is contained in:
parent
34c5e361ee
commit
084f2fcb05
24
main.go
24
main.go
@ -153,15 +153,29 @@ func renderCategories(objs map[string]Object) error {
|
|||||||
// FIXME: embed templates
|
// FIXME: embed templates
|
||||||
// FIXME: parse templates once at start
|
// FIXME: parse templates once at start
|
||||||
categoryIndexFilename := filepath.Join(categoryDir, "index.html")
|
categoryIndexFilename := filepath.Join(categoryDir, "index.html")
|
||||||
f, err := os.Create(categoryIndexFilename)
|
fmt.Printf("Write category Index file: %s\n", categoryIndexFilename)
|
||||||
if err != nil {
|
|
||||||
|
buf := bytes.NewBuffer(nil)
|
||||||
|
if err := tplCategoryIndex.Execute(buf, obj); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Write category Index file: %s\n", categoryIndexFilename)
|
// Sanitize HTML. This is not necessary, but allows to have content
|
||||||
|
// of all html files in same style.
|
||||||
|
{
|
||||||
|
query, err := goquery.NewDocumentFromReader(buf)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
if err := tplCategoryIndex.Execute(f, obj); err != nil {
|
html, err := query.Html()
|
||||||
return err
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := os.WriteFile(categoryIndexFilename, []byte(html), 0644); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user