Add themesDir option to configuration

themesDir can be used to change the default
path of the themes folder.

Fixes 1556
This commit is contained in:
digitalcraftsman 2015-11-23 20:44:59 +01:00 committed by Steve Francia
parent 40fccf2251
commit 47587321d9
6 changed files with 9 additions and 7 deletions

View file

@ -210,6 +210,7 @@ func LoadDefaultSettings() {
viper.SetDefault("ArchetypeDir", "archetypes") viper.SetDefault("ArchetypeDir", "archetypes")
viper.SetDefault("PublishDir", "public") viper.SetDefault("PublishDir", "public")
viper.SetDefault("DataDir", "data") viper.SetDefault("DataDir", "data")
viper.SetDefault("ThemesDir", "themes")
viper.SetDefault("DefaultLayout", "post") viper.SetDefault("DefaultLayout", "post")
viper.SetDefault("BuildDrafts", false) viper.SetDefault("BuildDrafts", false)
viper.SetDefault("BuildFuture", false) viper.SetDefault("BuildFuture", false)
@ -514,7 +515,7 @@ func getDirList() []string {
filepath.Walk(helpers.AbsPathify(viper.GetString("LayoutDir")), walker) filepath.Walk(helpers.AbsPathify(viper.GetString("LayoutDir")), walker)
filepath.Walk(helpers.AbsPathify(viper.GetString("StaticDir")), walker) filepath.Walk(helpers.AbsPathify(viper.GetString("StaticDir")), walker)
if helpers.ThemeSet() { if helpers.ThemeSet() {
filepath.Walk(helpers.AbsPathify("themes/"+viper.GetString("theme")), walker) filepath.Walk(helpers.AbsPathify(viper.GetString("themesDir")+"/"+viper.GetString("theme")), walker)
} }
return a return a

View file

@ -176,8 +176,8 @@ func NewTheme(cmd *cobra.Command, args []string) error {
return newUserError("theme name needs to be provided") return newUserError("theme name needs to be provided")
} }
createpath := helpers.AbsPathify(filepath.Join("themes", args[0])) createpath := helpers.AbsPathify(filepath.Join(viper.GetString("themesDir"), args[0]))
jww.INFO.Println("Creating theme at", createpath) jww.INFO.Println("creating theme at", createpath)
if x, _ := helpers.Exists(createpath, hugofs.SourceFs); x { if x, _ := helpers.Exists(createpath, hugofs.SourceFs); x {
return newUserError(createpath, "already exists") return newUserError(createpath, "already exists")

View file

@ -132,7 +132,7 @@ func FindArchetype(kind string) (outpath string) {
search := []string{helpers.AbsPathify(viper.GetString("archetypeDir"))} search := []string{helpers.AbsPathify(viper.GetString("archetypeDir"))}
if viper.GetString("theme") != "" { if viper.GetString("theme") != "" {
themeDir := filepath.Join(helpers.AbsPathify("themes/"+viper.GetString("theme")), "/archetypes/") themeDir := filepath.Join(helpers.AbsPathify(viper.GetString("themesDir")+"/"+viper.GetString("theme")), "/archetypes/")
if _, err := os.Stat(themeDir); os.IsNotExist(err) { if _, err := os.Stat(themeDir); os.IsNotExist(err) {
jww.ERROR.Println("Unable to find archetypes directory for theme :", viper.GetString("theme"), "in", themeDir) jww.ERROR.Println("Unable to find archetypes directory for theme :", viper.GetString("theme"), "in", themeDir)
} else { } else {

View file

@ -130,7 +130,8 @@ Following is a list of Hugo-defined variables that you can configure and their c
staticdir: "static" staticdir: "static"
# display memory and timing of different steps of the program # display memory and timing of different steps of the program
stepAnalysis: false stepAnalysis: false
# theme to use (located in /themes/THEMENAME/) # theme to use (located by default in /themes/THEMENAME/)
themesdir = "themes"
theme: "" theme: ""
title: "" title: ""
# if true, use /filename.html instead of /filename/ # if true, use /filename.html instead of /filename/

View file

@ -142,7 +142,7 @@ func GetStaticDirPath() string {
// If there is no theme, returns the empty string. // If there is no theme, returns the empty string.
func GetThemeDir() string { func GetThemeDir() string {
if ThemeSet() { if ThemeSet() {
return AbsPathify(filepath.Join("themes", viper.GetString("theme"))) return AbsPathify(filepath.Join(viper.GetString("themesDir"), viper.GetString("theme")))
} }
return "" return ""
} }

View file

@ -495,7 +495,7 @@ func (s *Site) absDataDir() string {
} }
func (s *Site) absThemeDir() string { func (s *Site) absThemeDir() string {
return helpers.AbsPathify("themes/" + viper.GetString("theme")) return helpers.AbsPathify(viper.GetString("themesDir") + "/" + viper.GetString("theme"))
} }
func (s *Site) absLayoutDir() string { func (s *Site) absLayoutDir() string {