mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-19 21:21:39 +02:00
Add data files support in themes
If duplicate keys, the main data dir wins. Fixes #892
This commit is contained in:
@@ -19,13 +19,13 @@ import (
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
bp "github.com/spf13/hugo/bufferpool"
|
||||
"github.com/spf13/viper"
|
||||
"io"
|
||||
"net"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
bp "github.com/spf13/hugo/bufferpool"
|
||||
)
|
||||
|
||||
// Filepath separator defined by os.Separator.
|
||||
@@ -100,6 +100,10 @@ func BytesToReader(in []byte) io.Reader {
|
||||
return bytes.NewReader(in)
|
||||
}
|
||||
|
||||
func ThemeSet() bool {
|
||||
return viper.GetString("theme") != ""
|
||||
}
|
||||
|
||||
// SliceToLower goes through the source slice and lowers all values.
|
||||
func SliceToLower(s []string) []string {
|
||||
if s == nil {
|
||||
|
@@ -178,6 +178,29 @@ func GetStaticDirPath() string {
|
||||
return AbsPathify(viper.GetString("StaticDir"))
|
||||
}
|
||||
|
||||
// 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) {
|
||||
return getThemeDirPath("static")
|
||||
}
|
||||
|
||||
// GetThemeStaticDirPath returns the theme's data dir path if theme is set.
|
||||
// If theme is set and the data dir doesn't exist, an error is returned.
|
||||
func GetThemeDataDirPath() (string, error) {
|
||||
return getThemeDirPath("data")
|
||||
}
|
||||
|
||||
func getThemeDirPath(path string) (string, error) {
|
||||
var themeDir string
|
||||
if ThemeSet() {
|
||||
themeDir = AbsPathify("themes/"+viper.GetString("theme")) + FilePathSeparator + 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)
|
||||
}
|
||||
}
|
||||
return themeDir, nil
|
||||
}
|
||||
|
||||
func GetThemesDirPath() string {
|
||||
return AbsPathify(filepath.Join("themes", viper.GetString("theme"), "static"))
|
||||
}
|
||||
|
Reference in New Issue
Block a user