ref: 7e0fa13faab4b77427b4f9ac392fda252b7b50ab
parent: 3d4e99ed50221d8dd1213eb587b8e7659e6d4b97
author: bogem <[email protected]>
date: Sun Feb 19 22:53:48 EST 2017
Get rid of some viper.Get* calls Enforce usage of PathSpec Fixes #3060 Updates #2728
--- a/hugolib/hugo_sites.go
+++ b/hugolib/hugo_sites.go
@@ -95,7 +95,7 @@
d = deps.New(cfg)
s.Deps = d
- if err := d.LoadResources(); err != nil {
+ if err = d.LoadResources(); err != nil {
return err
}
@@ -123,9 +123,9 @@
func (s *Site) withSiteTemplates(withTemplates ...func(templ tpl.Template) error) func(templ tpl.Template) error {
return func(templ tpl.Template) error {
- templ.LoadTemplates(s.absLayoutDir())
- if s.hasTheme() {
- templ.LoadTemplatesWithPrefix(s.absThemeDir()+"/layouts", "theme")
+ templ.LoadTemplates(s.PathSpec.GetLayoutDirPath())
+ if s.PathSpec.ThemeSet() {
+ templ.LoadTemplatesWithPrefix(s.PathSpec.GetThemeDir()+"/layouts", "theme")
}
for _, wt := range withTemplates {
--- a/hugolib/page.go
+++ b/hugolib/page.go
@@ -929,7 +929,7 @@
func (p *Page) RelPermalink() string {
link := p.getPermalink()
- if p.s.Cfg.GetBool("canonifyURLs") {
+ if p.s.Info.canonifyURLs {
// replacements for relpermalink with baseURL on the form http://myhost.com/sub/ will fail later on
// have to return the URL relative from baseURL
relpath, err := helpers.GetRelativePath(link.String(), string(p.Site.BaseURL))
--- a/hugolib/site.go
+++ b/hugolib/site.go
@@ -148,12 +148,11 @@
// Note: This is mainly used in single site tests.
func NewSite(cfg deps.DepsCfg) (*Site, error) {
s, err := newSite(cfg)
-
if err != nil {
return nil, err
}
- if err := applyDepsIfNeeded(cfg, s); err != nil {
+ if err = applyDepsIfNeeded(cfg, s); err != nil {
return nil, err
}
@@ -302,7 +301,7 @@
type SiteSocial map[string]string
-// Param is a convenience method to do lookups in Site's Params map.
+// Param is a convenience method to do lookups in SiteInfo's Params map.
//
// This method is also implemented on Page and Node.
func (s *SiteInfo) Param(key interface{}) (interface{}, error) {
@@ -903,7 +902,7 @@
return err
}
- staticDir := s.PathSpec.AbsPathify(s.Cfg.GetString("staticDir") + "/")
+ staticDir := s.PathSpec.GetStaticDirPath() + "/"
sp := source.NewSourceSpec(s.Cfg, s.Fs)
s.Source = sp.NewFilesystem(s.absContentDir(), staticDir)
@@ -992,13 +991,10 @@
s.Info.RSSLink = s.Info.permalinkStr(lang.GetString("rssURI"))
}
-func (s *Site) hasTheme() bool {
- return s.Cfg.GetString("theme") != ""
-}
-
func (s *Site) dataDir() string {
return s.Cfg.GetString("dataDir")
}
+
func (s *Site) absDataDir() string {
return s.PathSpec.AbsPathify(s.dataDir())
}
@@ -1023,10 +1019,10 @@
}
func (s *Site) getThemeI18nDir(path string) string {
- if !s.hasTheme() {
+ if !s.PathSpec.ThemeSet() {
return ""
}
- return s.getRealDir(s.PathSpec.AbsPathify(filepath.Join(s.themeDir(), s.i18nDir())), path)
+ return s.getRealDir(filepath.Join(s.PathSpec.GetThemeDir(), s.i18nDir()), path)
}
func (s *Site) isDataDirEvent(e fsnotify.Event) bool {
@@ -1041,28 +1037,16 @@
}
func (s *Site) getThemeDataDir(path string) string {
- if !s.hasTheme() {
+ if !s.PathSpec.ThemeSet() {
return ""
}
- return s.getRealDir(s.PathSpec.AbsPathify(filepath.Join(s.themeDir(), s.dataDir())), path)
+ return s.getRealDir(filepath.Join(s.PathSpec.GetThemeDir(), s.dataDir()), path)
}
-func (s *Site) themeDir() string {
- return s.Cfg.GetString("themesDir") + "/" + s.Cfg.GetString("theme")
-}
-
-func (s *Site) absThemeDir() string {
- return s.PathSpec.AbsPathify(s.themeDir())
-}
-
func (s *Site) layoutDir() string {
return s.Cfg.GetString("layoutDir")
}
-func (s *Site) absLayoutDir() string {
- return s.PathSpec.AbsPathify(s.layoutDir())
-}
-
func (s *Site) isLayoutDirEvent(e fsnotify.Event) bool {
if s.getLayoutDir(e.Name) != "" {
return true
@@ -1071,14 +1055,14 @@
}
func (s *Site) getLayoutDir(path string) string {
- return s.getRealDir(s.absLayoutDir(), path)
+ return s.getRealDir(s.PathSpec.GetLayoutDirPath(), path)
}
func (s *Site) getThemeLayoutDir(path string) string {
- if !s.hasTheme() {
+ if !s.PathSpec.ThemeSet() {
return ""
}
- return s.getRealDir(s.PathSpec.AbsPathify(filepath.Join(s.themeDir(), s.layoutDir())), path)
+ return s.getRealDir(filepath.Join(s.PathSpec.GetThemeDir(), s.layoutDir()), path)
}
func (s *Site) absContentDir() string {
@@ -1671,7 +1655,7 @@
}
func (s *Site) appendThemeTemplates(in []string) []string {
- if !s.hasTheme() {
+ if !s.PathSpec.ThemeSet() {
return in
}
@@ -1798,8 +1782,9 @@
}
transformLinks := transform.NewEmptyTransforms()
+ relativeURLs := s.Cfg.GetBool("relativeURLs")
- if s.Cfg.GetBool("relativeURLs") || s.Cfg.GetBool("canonifyURLs") {
+ if relativeURLs || s.Info.canonifyURLs {
transformLinks = append(transformLinks, transform.AbsURL)
}
@@ -1816,18 +1801,18 @@
var path []byte
- if s.Cfg.GetBool("relativeURLs") {
+ if relativeURLs {
translated, err := pageTarget.(target.OptionalTranslator).TranslateRelative(dest)
if err != nil {
return err
}
path = []byte(helpers.GetDottedRelativePath(translated))
- } else if s.Cfg.GetBool("canonifyURLs") {
- s := s.Cfg.GetString("baseURL")
- if !strings.HasSuffix(s, "/") {
- s += "/"
+ } else if s.Info.canonifyURLs {
+ url := s.Cfg.GetString("baseURL")
+ if !strings.HasSuffix(url, "/") {
+ url += "/"
}
- path = []byte(s)
+ path = []byte(url)
}
transformer := transform.NewChain(transformLinks...)