Browse Source

Make output dir configurable

master
arnaucube 2 years ago
parent
commit
add29da9e4
5 changed files with 12 additions and 7 deletions
  1. BIN
      bin/blogo-amd64-darwin
  2. BIN
      bin/blogo-amd64-linux
  3. BIN
      bin/blogo-amd64.exe
  4. +8
    -7
      main.go
  5. +4
    -0
      readConfig.go

BIN
bin/blogo-amd64-darwin


BIN
bin/blogo-amd64-linux


BIN
bin/blogo-amd64.exe


+ 8
- 7
main.go

@ -12,9 +12,9 @@ import (
"github.com/gomarkdown/markdown/parser" "github.com/gomarkdown/markdown/parser"
) )
const version = "v0_20220501"
const version = "v0_20220503"
const directory = "blogo-input" const directory = "blogo-input"
const outputDir = "public"
const defaultOutputDir = "public"
func main() { func main() {
devMode := flag.Bool("d", false, "dev mode") devMode := flag.Bool("d", false, "dev mode")
@ -22,7 +22,8 @@ func main() {
flag.Parse() flag.Parse()
fmt.Println("Blogo version:", version) fmt.Println("Blogo version:", version)
_ = os.Mkdir(outputDir, os.ModePerm)
readConfig(directory + "/blogo.json")
_ = os.Mkdir(config.OutputDir, os.ModePerm)
fmt.Println("devMode:", *devMode) fmt.Println("devMode:", *devMode)
generateHTML() generateHTML()
@ -35,7 +36,7 @@ func main() {
// go watch("./public") // go watch("./public")
// serve files // 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", fmt.Printf("Blog being served in: \n http://127.0.0.1:%s\n http://localhost:%s\n",
*port, *port) *port, *port)
log.Fatal(http.ListenAndServe(":"+*port, fs)) log.Fatal(http.ListenAndServe(":"+*port, fs))
@ -75,7 +76,7 @@ func generateHTML() {
m["[blogo-img]"] = config.AbsoluteUrl + "/" + config.MetaImg m["[blogo-img]"] = config.AbsoluteUrl + "/" + config.MetaImg
m["[blogo-link]"] = config.AbsoluteUrl m["[blogo-link]"] = config.AbsoluteUrl
r := putHTMLToTemplate(indexTemplate, m) r := putHTMLToTemplate(indexTemplate, m)
writeFile(outputDir+"/"+"index.html", r)
writeFile(config.OutputDir+"/"+"index.html", r)
// generate posts pages // generate posts pages
@ -97,13 +98,13 @@ func generateHTML() {
m["[blogo-img]"] = config.AbsoluteUrl + "/" + post.MetaImg m["[blogo-img]"] = config.AbsoluteUrl + "/" + post.MetaImg
r := putHTMLToTemplate(indexTemplate, m) r := putHTMLToTemplate(indexTemplate, m)
writeFile(outputDir+"/"+filename+".html", r)
writeFile(config.OutputDir+"/"+filename+".html", r)
} }
//copy raw //copy raw
fmt.Println("copying raw:") fmt.Println("copying raw:")
for _, dir := range config.CopyRaw { for _, dir := range config.CopyRaw {
copyRaw(directory+"/"+dir, outputDir+"/")
copyRaw(directory+"/"+dir, config.OutputDir+"/")
} }
} }

+ 4
- 0
readConfig.go

@ -25,6 +25,7 @@ type Config struct {
PostThumbTemplate string `json:"postThumbTemplate"` PostThumbTemplate string `json:"postThumbTemplate"`
Posts []Post `json:"posts"` Posts []Post `json:"posts"`
CopyRaw []string `json:"copyRaw"` CopyRaw []string `json:"copyRaw"`
OutputDir string `json:"outputDir"`
} }
var config Config var config Config
@ -37,4 +38,7 @@ func readConfig(path string) {
if config.PostsDir != "" { if config.PostsDir != "" {
config.PostsDir += "/" config.PostsDir += "/"
} }
if config.OutputDir == "" {
config.OutputDir = defaultOutputDir
}
} }

Loading…
Cancel
Save