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

40 lines
660 B
Go
Raw Normal View History

package main
import (
2023-02-14 12:50:14 -05:00
"fmt"
2022-08-30 17:52:53 -04:00
"html/template"
"os"
2022-08-30 17:52:53 -04:00
"github.com/avelino/awesome-go/pkg/markdown"
)
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 := os.ReadFile(srcFilename)
2023-02-03 20:39:51 -05:00
if err != nil {
return err
}
2023-02-14 15:26:32 -05:00
body, err := markdown.ToHTML(input)
2023-02-03 20:39:51 -05:00
if err != nil {
return err
}
2022-08-30 17:52:53 -04:00
c := &content{Body: template.HTML(body)}
2023-02-03 20:39:51 -05:00
f, err := os.Create(outFilename)
if err != nil {
return err
}
2023-02-14 12:50:14 -05:00
fmt.Printf("Write Index file: %s\n", outIndexFile)
2023-02-14 13:12:57 -05:00
if err := tplIndex.Execute(f, c); err != nil {
2023-02-03 20:39:51 -05:00
return err
}
return nil
}