Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Anderson <jonathan.anderson@ieee.org>2015-06-19 16:26:32 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2015-06-25 19:05:43 +0300
commit1058cb17d14ea404838e759ebe028e3ad992668a (patch)
tree1212045d4c4db655a7b8dff1c5f6978020840632 /helpers
parent0987e98db368611ceae6e83f14bbf57b8330c110 (diff)
Refactor theme path helper functions.
Reduce duplication (`x + FilePathSeparator + y` a few lines away from `filepath.Join(x, y)`) and add a `GetThemeDir()` function to get the current theme's directory. Also add a comment complaining about the `GetThemesDirPath()` function, which doesn't seem to do what its name would suggest. This might be a candidate for deprecation?
Diffstat (limited to 'helpers')
-rw-r--r--helpers/path.go16
1 files changed, 14 insertions, 2 deletions
diff --git a/helpers/path.go b/helpers/path.go
index 2d9502c8a..ba6d0e9d1 100644
--- a/helpers/path.go
+++ b/helpers/path.go
@@ -204,6 +204,15 @@ func GetStaticDirPath() string {
return AbsPathify(viper.GetString("StaticDir"))
}
+// Get the root directory of the current theme, if there is one.
+// If there is no theme, returns the empty string.
+func GetThemeDir() string {
+ if ThemeSet() {
+ return AbsPathify(filepath.Join("themes", viper.GetString("theme")))
+ }
+ return ""
+}
+
// GetThemeStaticDirPath returns the theme's static dir path if theme is set.
// If theme is set and the static dir doesn't exist, an error is returned.
func GetThemeStaticDirPath() (string, error) {
@@ -219,7 +228,7 @@ func GetThemeDataDirPath() (string, error) {
func getThemeDirPath(path string) (string, error) {
var themeDir string
if ThemeSet() {
- themeDir = AbsPathify("themes/"+viper.GetString("theme")) + FilePathSeparator + path
+ themeDir = filepath.Join(GetThemeDir(), path)
if _, err := os.Stat(themeDir); os.IsNotExist(err) {
return "", fmt.Errorf("Unable to find %s directory for theme %s in %s", path, viper.GetString("theme"), themeDir)
}
@@ -227,8 +236,11 @@ func getThemeDirPath(path string) (string, error) {
return themeDir, nil
}
+// Get the 'static' directory of the current theme, if there is one.
+// Ignores underlying errors. Candidate for deprecation?
func GetThemesDirPath() string {
- return AbsPathify(filepath.Join("themes", viper.GetString("theme"), "static"))
+ dir, _ := getThemeDirPath("static")
+ return dir
}
func MakeStaticPathRelative(inPath string) (string, error) {