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
22
main.go
22
main.go
@ -153,16 +153,30 @@ func renderCategories(objs map[string]Object) error {
|
||||
// FIXME: embed templates
|
||||
// FIXME: parse templates once at start
|
||||
categoryIndexFilename := filepath.Join(categoryDir, "index.html")
|
||||
f, err := os.Create(categoryIndexFilename)
|
||||
fmt.Printf("Write category Index file: %s\n", categoryIndexFilename)
|
||||
|
||||
buf := bytes.NewBuffer(nil)
|
||||
if err := tplCategoryIndex.Execute(buf, obj); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
fmt.Printf("Write category Index file: %s\n", categoryIndexFilename)
|
||||
|
||||
if err := tplCategoryIndex.Execute(f, obj); err != nil {
|
||||
html, err := query.Html()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := os.WriteFile(categoryIndexFilename, []byte(html), 0644); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
Loading…
Reference in New Issue
Block a user