1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
package main
import (
"fmt"
"log"
"os"
"path/filepath"
"strings"
"github.com/gomarkdown/markdown"
)
func main() {
path := filepath.Join("./content/")
files, err := os.ReadDir(path)
if err != nil {
log.Fatalf("Error %s", err)
}
for _, f := range files {
filePath := filepath.Join(path, f.Name())
if !f.IsDir() && strings.HasSuffix(f.Name(), ".md") {
fmt.Printf("Found content: %s", f.Name())
htmlContent := convertToHtml(filePath)
htmlPath := strings.Replace(filePath, ".md", ".html", 1)
os.WriteFile(htmlPath, htmlContent, 0o777)
fmt.Printf("Wrote file: %s", htmlPath)
}
}
}
func convertToHtml(path string) []byte {
mds, err := os.ReadFile(path)
if err != nil {
log.Fatalf("Error %s", err)
}
md := []byte(mds)
html := markdown.ToHTML(md, nil, nil)
// fmt.Printf("--- Markdown:\n%s\n\n--- HTML:\n%s\n", md, html)
return html
}
|