Make output dir configurable
arnaucube root@arnaucube.com
Tue, 03 May 2022 14:47:45 +0200
5 files changed,
12 insertions(+),
7 deletions(-)
M
main.go
→
main.go
@@ -12,9 +12,9 @@ "github.com/gomarkdown/markdown"
"github.com/gomarkdown/markdown/parser" ) -const version = "v0_20220501" +const version = "v0_20220503" const directory = "blogo-input" -const outputDir = "public" +const defaultOutputDir = "public" func main() { devMode := flag.Bool("d", false, "dev mode")@@ -22,7 +22,8 @@ port := flag.String("p", "8080", "port (only for dev mode)")
flag.Parse() fmt.Println("Blogo version:", version) - _ = os.Mkdir(outputDir, os.ModePerm) + readConfig(directory + "/blogo.json") + _ = os.Mkdir(config.OutputDir, os.ModePerm) fmt.Println("devMode:", *devMode) generateHTML()@@ -35,7 +36,7 @@ // TODO public not watched, until a way to force browser refresh
// go watch("./public") // serve files - fs := http.FileServer(http.Dir("public")) + fs := http.FileServer(http.Dir(config.OutputDir)) fmt.Printf("Blog being served in: \n http://127.0.0.1:%s\n http://localhost:%s\n", *port, *port) log.Fatal(http.ListenAndServe(":"+*port, fs))@@ -75,7 +76,7 @@ m["[blogo-summary]"] = config.MetaDescr
m["[blogo-img]"] = config.AbsoluteUrl + "/" + config.MetaImg m["[blogo-link]"] = config.AbsoluteUrl r := putHTMLToTemplate(indexTemplate, m) - writeFile(outputDir+"/"+"index.html", r) + writeFile(config.OutputDir+"/"+"index.html", r) // generate posts pages@@ -97,13 +98,13 @@ m["[blogo-link]"] = config.AbsoluteUrl + "/" + filename + ".html"
m["[blogo-img]"] = config.AbsoluteUrl + "/" + post.MetaImg r := putHTMLToTemplate(indexTemplate, m) - writeFile(outputDir+"/"+filename+".html", r) + writeFile(config.OutputDir+"/"+filename+".html", r) } //copy raw fmt.Println("copying raw:") for _, dir := range config.CopyRaw { - copyRaw(directory+"/"+dir, outputDir+"/") + copyRaw(directory+"/"+dir, config.OutputDir+"/") } }
M
readConfig.go
→
readConfig.go
@@ -25,6 +25,7 @@ IndexTemplate string `json:"indexTemplate"`
PostThumbTemplate string `json:"postThumbTemplate"` Posts []Post `json:"posts"` CopyRaw []string `json:"copyRaw"` + OutputDir string `json:"outputDir"` } var config Config@@ -36,5 +37,8 @@ content := string(file)
json.Unmarshal([]byte(content), &config) if config.PostsDir != "" { config.PostsDir += "/" + } + if config.OutputDir == "" { + config.OutputDir = defaultOutputDir } }