From 76673e2816efad1d42d0ae5536240fe32467e870 Mon Sep 17 00:00:00 2001 From: Himanshu Sardana Date: Wed, 18 Mar 2026 18:34:09 +0000 Subject: feat: copy theme files over to output dir --- main.go | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'main.go') diff --git a/main.go b/main.go index 69f8981..ce81637 100644 --- a/main.go +++ b/main.go @@ -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 +} -- cgit v1.3.1