Skip to content

Commit beac215

Browse files
committed
Added creating of content directories of they are not created already.
1 parent 6fd661e commit beac215

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

filenames/filenames.go

+18-1
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,30 @@ var (
4040
// For users (this is a url string)
4141
DefaultUserImageFilename = "/public/images/user-image.jpg"
4242
DefaultUserCoverFilename = "/public/images/user-cover.jpg"
43+
44+
// Create content directories if they are not created already
45+
_ = createDirectories()
4346
)
4447

48+
func createDirectories() error {
49+
paths := []string{filepath.Join(customPath, "content", "data"), filepath.Join(customPath, "content", "themes"), filepath.Join(customPath, "content", "images"), filepath.Join(customPath, "content", "https")}
50+
for _, path := range paths {
51+
if _, err := os.Stat(path); os.IsNotExist(err) {
52+
log.Println("Creating " + path)
53+
err := os.MkdirAll(path, 0776)
54+
if err != nil {
55+
log.Fatal("Error: Couldn't create directory " + path + ": " + err.Error())
56+
return err
57+
}
58+
}
59+
}
60+
return nil
61+
}
62+
4563
func initializeWorkingDirectory() error {
4664
// Check if a custom content path has been provided by the user
4765
flag.StringVar(&customPath, "custom-path", "", "Specify a custom path to store content files. Note: Journey needs read and write access to that path.")
4866
flag.Parse()
49-
log.Println(customPath)
5067

5168
// Set working directory to the path this executable is in
5269
executablePath, err := osext.ExecutableFolder()

main.go

+2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ func checkHttpsCertificates() {
3333

3434
func main() {
3535
// Setup
36+
3637
// GOMAXPROCS - Maybe not needed
3738
runtime.GOMAXPROCS(runtime.NumCPU())
39+
3840
// Write log to file
3941
logFile, err := os.OpenFile(filenames.LogFilename, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
4042
if err != nil {

templates/generation.go

+6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/kabukky/journey/filenames"
88
"github.com/kabukky/journey/structure"
99
"io/ioutil"
10+
"log"
1011
"os"
1112
"path/filepath"
1213
"regexp"
@@ -197,6 +198,11 @@ func Generate() error {
197198
// First clear compiledTemplates map (theme could have been changed)
198199
compiledTemplates.m = make(map[string]*Helper)
199200
currentThemePath := filepath.Join(filenames.ThemesFilepath, *activeTheme)
201+
// Check if the theme folder exists
202+
if _, err := os.Stat(currentThemePath); os.IsNotExist(err) {
203+
log.Fatal("Error: Couldn't find theme files in " + currentThemePath + ": " + err.Error())
204+
return err
205+
}
200206
err = filepath.Walk(currentThemePath, inspectTemplateFile)
201207
if err != nil {
202208
return err

0 commit comments

Comments
 (0)