hugolib: Enable override of theme base template only

This commit fixes the base template lookup order to match the behaviour of regular templates.

```
1. <current-path>/<template-name>-baseof.<suffix>, e.g. list-baseof.<suffix>.
2. <current-path>/baseof.<suffix>
3. _default/<template-name>-baseof.<suffix>, e.g. list-baseof.<suffix>.
4. _default/baseof.<suffix>

For each of the steps above, it will first look in the project, then, if theme is set,
in the theme's layouts folder.
```

Fixes #2783
This commit is contained in:
Bjørn Erik Pedersen
2016-12-14 20:12:03 +01:00
parent 596bbea815
commit a3a67163f9
3 changed files with 204 additions and 17 deletions

View File

@@ -157,6 +157,12 @@ func AbsPathify(inPath string) string {
return filepath.Clean(filepath.Join(viper.GetString("workingDir"), inPath))
}
// GetLayoutDirPath returns the absolute path to the layout file dir
// for the current Hugo project.
func GetLayoutDirPath() string {
return AbsPathify(viper.GetString("layoutDir"))
}
// GetStaticDirPath returns the absolute path to the static file dir
// for the current Hugo project.
func GetStaticDirPath() string {
@@ -172,6 +178,15 @@ func GetThemeDir() string {
return ""
}
// GetRelativeThemeDir gets the relative root directory of the current theme, if there is one.
// If there is no theme, returns the empty string.
func GetRelativeThemeDir() string {
if ThemeSet() {
return strings.TrimPrefix(filepath.Join(viper.GetString("themesDir"), viper.GetString("theme")), FilePathSeparator)
}
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) {