diff options
| author | Himanshu Sardana <himanshusardana2005@gmail.com> | 2026-03-18 18:34:09 +0000 |
|---|---|---|
| committer | Himanshu Sardana <himanshusardana2005@gmail.com> | 2026-03-18 18:34:09 +0000 |
| commit | 76673e2816efad1d42d0ae5536240fe32467e870 (patch) | |
| tree | 5f11d65c4e394f057cd1552834132873083cb2ce /main.go | |
| parent | 0d4438337f055d52f0aa819b03ae370e4b571dd8 (diff) | |
feat: copy theme files over to output dir
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 31 |
1 files changed, 30 insertions, 1 deletions
@@ -3,6 +3,7 @@ package main import ( "fmt" "html/template" + "io" "io/fs" "log" "net/http" @@ -27,10 +28,15 @@ func main() { contentDir := "./content" outputDir := "./output" + themeName := "modern-light" + args := os.Args if len(args) > 1 { switch args[1] { case "serve": + + copyFile("./themes/"+themeName+".css", "./output/style.css") + fs := http.FileServer(http.Dir("./output/")) http.Handle("/", fs) @@ -70,7 +76,9 @@ func main() { if err != nil { log.Fatalf("Error computing relative path: %s", err) } - outputFilePath := filepath.Join(outputDir, strings.Replace(relPath, ".md", ".html", 1)) + // test.md -> test.html + // test.md -> test/index.html + outputFilePath := filepath.Join(outputDir, strings.Replace(relPath, ".md", "/index.html", 1)) err = os.MkdirAll(filepath.Dir(outputFilePath), 0o755) if err != nil { @@ -111,3 +119,24 @@ func convertToHtml(path string) (string, []byte) { html := markdown.ToHTML(rest, nil, nil) return matter.Title, html } + +func copyFile(src, dst string) error { + in, err := os.Open(src) + if err != nil { + return err + } + defer in.Close() + + if err := os.MkdirAll(filepath.Dir(dst), os.ModePerm); err != nil { + return err + } + + out, err := os.Create(dst) + if err != nil { + return err + } + defer out.Close() + + _, err = io.Copy(out, in) + return err +} |
