diff options
| author | Himanshu Sardana <himanshusardana2005@gmail.com> | 2026-03-16 18:44:26 +0000 |
|---|---|---|
| committer | Himanshu Sardana <himanshusardana2005@gmail.com> | 2026-03-16 18:44:26 +0000 |
| commit | 11a5a261a0d2c833a9bc12cb0c86e5b1e624b7b1 (patch) | |
| tree | 5e30a12a9337d65f1c4a3006d72b6ca1fe5ecae2 /main.go | |
| parent | 86f46ef995ca47a33590366b41dc299619bf81f0 (diff) | |
feat: read and convert files from content dir
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 28 |
1 files changed, 23 insertions, 5 deletions
@@ -2,22 +2,40 @@ package main import ( "fmt" + "log" "os" "path/filepath" + "strings" "github.com/gomarkdown/markdown" - // "github.com/gomarkdown/markdown/html" - // "github.com/gomarkdown/markdown/parser" ) func main() { - path := filepath.Join("./test.md") + 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 := filePath + ".html" + os.WriteFile(htmlPath, htmlContent, 0o777) + fmt.Printf("Wrote file: %s", htmlPath) + } + } +} + +func convertToHtml(path string) []byte { mds, err := os.ReadFile(path) if err != nil { - fmt.Println("Error %s", err) + 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) + // fmt.Printf("--- Markdown:\n%s\n\n--- HTML:\n%s\n", md, html) + return html } |
