Skip to content

Commit

Permalink
Added creating of content directories of they are not created already.
Browse files Browse the repository at this point in the history
  • Loading branch information
kabukky committed Apr 1, 2015
1 parent 6fd661e commit beac215
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
19 changes: 18 additions & 1 deletion filenames/filenames.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,30 @@ var (
// For users (this is a url string)
DefaultUserImageFilename = "/public/images/user-image.jpg"
DefaultUserCoverFilename = "/public/images/user-cover.jpg"

// Create content directories if they are not created already
_ = createDirectories()
)

func createDirectories() error {
paths := []string{filepath.Join(customPath, "content", "data"), filepath.Join(customPath, "content", "themes"), filepath.Join(customPath, "content", "images"), filepath.Join(customPath, "content", "https")}
for _, path := range paths {
if _, err := os.Stat(path); os.IsNotExist(err) {
log.Println("Creating " + path)
err := os.MkdirAll(path, 0776)
if err != nil {
log.Fatal("Error: Couldn't create directory " + path + ": " + err.Error())
return err
}
}
}
return nil
}

func initializeWorkingDirectory() error {
// Check if a custom content path has been provided by the user
flag.StringVar(&customPath, "custom-path", "", "Specify a custom path to store content files. Note: Journey needs read and write access to that path.")
flag.Parse()
log.Println(customPath)

// Set working directory to the path this executable is in
executablePath, err := osext.ExecutableFolder()
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ func checkHttpsCertificates() {

func main() {
// Setup

// GOMAXPROCS - Maybe not needed
runtime.GOMAXPROCS(runtime.NumCPU())

// Write log to file
logFile, err := os.OpenFile(filenames.LogFilename, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
Expand Down
6 changes: 6 additions & 0 deletions templates/generation.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/kabukky/journey/filenames"
"github.com/kabukky/journey/structure"
"io/ioutil"
"log"
"os"
"path/filepath"
"regexp"
Expand Down Expand Up @@ -197,6 +198,11 @@ func Generate() error {
// First clear compiledTemplates map (theme could have been changed)
compiledTemplates.m = make(map[string]*Helper)
currentThemePath := filepath.Join(filenames.ThemesFilepath, *activeTheme)
// Check if the theme folder exists
if _, err := os.Stat(currentThemePath); os.IsNotExist(err) {
log.Fatal("Error: Couldn't find theme files in " + currentThemePath + ": " + err.Error())
return err
}
err = filepath.Walk(currentThemePath, inspectTemplateFile)
if err != nil {
return err
Expand Down

0 comments on commit beac215

Please sign in to comment.