2020-09-24 17:21:00 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-02-14 12:50:14 -05:00
|
|
|
"fmt"
|
2022-08-30 17:52:53 -04:00
|
|
|
"html/template"
|
2021-12-22 08:12:40 -05:00
|
|
|
"os"
|
2020-09-24 17:21:00 -04:00
|
|
|
|
2022-08-30 17:52:53 -04:00
|
|
|
"github.com/avelino/awesome-go/pkg/markdown"
|
2020-09-24 17:21:00 -04:00
|
|
|
)
|
|
|
|
|
2023-02-14 18:19:35 -05:00
|
|
|
// convertAndRenderIndex generate site html (index.html) from markdown file
|
|
|
|
func convertAndRenderIndex(srcFilename, outFilename string) error {
|
2023-02-14 12:30:51 -05:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
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 16:59:11 -05:00
|
|
|
data := map[string]interface{}{
|
|
|
|
"Body": template.HTML(body),
|
|
|
|
}
|
|
|
|
if err := tplIndex.Execute(f, data); err != nil {
|
2023-02-03 20:39:51 -05:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2021-12-22 08:12:40 -05:00
|
|
|
}
|