-
Notifications
You must be signed in to change notification settings - Fork 203
/
Copy pathfilenames.go
91 lines (77 loc) · 2.87 KB
/
filenames.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package filenames
import (
"github.com/kabukky/journey/flags"
"github.com/kardianos/osext"
"log"
"os"
"path/filepath"
)
var (
// Determine the path the Journey executable is in - needed to load relative assets
ExecutablePath = determineExecutablePath()
// Determine the path the the assets folder (default: Journey root folder)
AssetPath = determineContentPath()
// For assets that are created, changed, our user-provided while running journey
ConfigFilename = filepath.Join(AssetPath, "config.json")
ContentFilepath = filepath.Join(AssetPath, "content")
DatabaseFilepath = filepath.Join(ContentFilepath, "data")
DatabaseFilename = filepath.Join(ContentFilepath, "data", "journey.db")
ThemesFilepath = filepath.Join(ContentFilepath, "themes")
ImagesFilepath = filepath.Join(ContentFilepath, "images")
PluginsFilepath = filepath.Join(ContentFilepath, "plugins")
PagesFilepath = filepath.Join(ContentFilepath, "pages")
// For https
HttpsFilepath = filepath.Join(ContentFilepath, "https")
HttpsCertFilename = filepath.Join(ContentFilepath, "https", "cert.pem")
HttpsKeyFilename = filepath.Join(ContentFilepath, "https", "key.pem")
//For built-in files (e.g. the admin interface)
AdminFilepath = filepath.Join(ExecutablePath, "built-in", "admin")
PublicFilepath = filepath.Join(ExecutablePath, "built-in", "public")
HbsFilepath = filepath.Join(ExecutablePath, "built-in", "hbs")
// For handlebars (this is a url string)
JqueryFilename = "/public/jquery/jquery.js"
// For blog (this is a url string)
// TODO: This is not used at the moment because it is still hard-coded into the create database string
DefaultBlogLogoFilename = "/public/images/blog-logo.jpg"
DefaultBlogCoverFilename = "/public/images/blog-cover.jpg"
// For users (this is a url string)
DefaultUserImageFilename = "/public/images/user-image.jpg"
DefaultUserCoverFilename = "/public/images/user-cover.jpg"
)
func init() {
// Create content directories if they are not created already
err := createDirectories()
if err != nil {
log.Fatal("Error: Couldn't create directories:", err)
}
}
func createDirectories() error {
paths := []string{DatabaseFilepath, ThemesFilepath, ImagesFilepath, HttpsFilepath, PluginsFilepath, PagesFilepath}
for _, path := range paths {
if _, err := os.Stat(path); os.IsNotExist(err) {
log.Println("Creating " + path)
err := os.MkdirAll(path, 0776)
if err != nil {
return err
}
}
}
return nil
}
func determineContentPath() string {
contentPath := ""
if flags.CustomPath != "" {
contentPath = flags.CustomPath
} else {
contentPath = determineExecutablePath()
}
return contentPath
}
func determineExecutablePath() string {
// Get the path this executable is located in
executablePath, err := osext.ExecutableFolder()
if err != nil {
log.Fatal("Error: Couldn't determine what directory this executable is in:", err)
}
return executablePath
}