mirror of
https://github.com/gohugoio/hugo.git
synced 2024-07-02 15:20:28 +00:00
Get rid of some viper.Get* calls
Enforce usage of PathSpec Fixes #3060 Updates #2728
This commit is contained in:
parent
3d4e99ed50
commit
7e0fa13faa
|
@ -95,7 +95,7 @@ func applyDepsIfNeeded(cfg deps.DepsCfg, sites ...*Site) error {
|
||||||
d = deps.New(cfg)
|
d = deps.New(cfg)
|
||||||
s.Deps = d
|
s.Deps = d
|
||||||
|
|
||||||
if err := d.LoadResources(); err != nil {
|
if err = d.LoadResources(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,9 +123,9 @@ func NewHugoSites(cfg deps.DepsCfg) (*HugoSites, error) {
|
||||||
|
|
||||||
func (s *Site) withSiteTemplates(withTemplates ...func(templ tpl.Template) error) func(templ tpl.Template) error {
|
func (s *Site) withSiteTemplates(withTemplates ...func(templ tpl.Template) error) func(templ tpl.Template) error {
|
||||||
return func(templ tpl.Template) error {
|
return func(templ tpl.Template) error {
|
||||||
templ.LoadTemplates(s.absLayoutDir())
|
templ.LoadTemplates(s.PathSpec.GetLayoutDirPath())
|
||||||
if s.hasTheme() {
|
if s.PathSpec.ThemeSet() {
|
||||||
templ.LoadTemplatesWithPrefix(s.absThemeDir()+"/layouts", "theme")
|
templ.LoadTemplatesWithPrefix(s.PathSpec.GetThemeDir()+"/layouts", "theme")
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, wt := range withTemplates {
|
for _, wt := range withTemplates {
|
||||||
|
|
|
@ -929,7 +929,7 @@ func (p *Page) URL() string {
|
||||||
func (p *Page) RelPermalink() string {
|
func (p *Page) RelPermalink() string {
|
||||||
link := p.getPermalink()
|
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
|
// replacements for relpermalink with baseURL on the form http://myhost.com/sub/ will fail later on
|
||||||
// have to return the URL relative from baseURL
|
// have to return the URL relative from baseURL
|
||||||
relpath, err := helpers.GetRelativePath(link.String(), string(p.Site.BaseURL))
|
relpath, err := helpers.GetRelativePath(link.String(), string(p.Site.BaseURL))
|
||||||
|
|
|
@ -148,12 +148,11 @@ func newSite(cfg deps.DepsCfg) (*Site, error) {
|
||||||
// Note: This is mainly used in single site tests.
|
// Note: This is mainly used in single site tests.
|
||||||
func NewSite(cfg deps.DepsCfg) (*Site, error) {
|
func NewSite(cfg deps.DepsCfg) (*Site, error) {
|
||||||
s, err := newSite(cfg)
|
s, err := newSite(cfg)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := applyDepsIfNeeded(cfg, s); err != nil {
|
if err = applyDepsIfNeeded(cfg, s); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -302,7 +301,7 @@ func newSiteInfo(cfg siteBuilderCfg) SiteInfo {
|
||||||
// linkedin
|
// linkedin
|
||||||
type SiteSocial map[string]string
|
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.
|
// This method is also implemented on Page and Node.
|
||||||
func (s *SiteInfo) Param(key interface{}) (interface{}, error) {
|
func (s *SiteInfo) Param(key interface{}) (interface{}, error) {
|
||||||
|
@ -903,7 +902,7 @@ func (s *Site) initialize() (err error) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
staticDir := s.PathSpec.AbsPathify(s.Cfg.GetString("staticDir") + "/")
|
staticDir := s.PathSpec.GetStaticDirPath() + "/"
|
||||||
|
|
||||||
sp := source.NewSourceSpec(s.Cfg, s.Fs)
|
sp := source.NewSourceSpec(s.Cfg, s.Fs)
|
||||||
s.Source = sp.NewFilesystem(s.absContentDir(), staticDir)
|
s.Source = sp.NewFilesystem(s.absContentDir(), staticDir)
|
||||||
|
@ -992,13 +991,10 @@ func (s *Site) initializeSiteInfo() {
|
||||||
s.Info.RSSLink = s.Info.permalinkStr(lang.GetString("rssURI"))
|
s.Info.RSSLink = s.Info.permalinkStr(lang.GetString("rssURI"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Site) hasTheme() bool {
|
|
||||||
return s.Cfg.GetString("theme") != ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Site) dataDir() string {
|
func (s *Site) dataDir() string {
|
||||||
return s.Cfg.GetString("dataDir")
|
return s.Cfg.GetString("dataDir")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Site) absDataDir() string {
|
func (s *Site) absDataDir() string {
|
||||||
return s.PathSpec.AbsPathify(s.dataDir())
|
return s.PathSpec.AbsPathify(s.dataDir())
|
||||||
}
|
}
|
||||||
|
@ -1023,10 +1019,10 @@ func (s *Site) getI18nDir(path string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Site) getThemeI18nDir(path string) string {
|
func (s *Site) getThemeI18nDir(path string) string {
|
||||||
if !s.hasTheme() {
|
if !s.PathSpec.ThemeSet() {
|
||||||
return ""
|
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 {
|
func (s *Site) isDataDirEvent(e fsnotify.Event) bool {
|
||||||
|
@ -1041,28 +1037,16 @@ func (s *Site) getDataDir(path string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Site) getThemeDataDir(path string) string {
|
func (s *Site) getThemeDataDir(path string) string {
|
||||||
if !s.hasTheme() {
|
if !s.PathSpec.ThemeSet() {
|
||||||
return ""
|
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 {
|
func (s *Site) layoutDir() string {
|
||||||
return s.Cfg.GetString("layoutDir")
|
return s.Cfg.GetString("layoutDir")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Site) absLayoutDir() string {
|
|
||||||
return s.PathSpec.AbsPathify(s.layoutDir())
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Site) isLayoutDirEvent(e fsnotify.Event) bool {
|
func (s *Site) isLayoutDirEvent(e fsnotify.Event) bool {
|
||||||
if s.getLayoutDir(e.Name) != "" {
|
if s.getLayoutDir(e.Name) != "" {
|
||||||
return true
|
return true
|
||||||
|
@ -1071,14 +1055,14 @@ func (s *Site) isLayoutDirEvent(e fsnotify.Event) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Site) getLayoutDir(path string) string {
|
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 {
|
func (s *Site) getThemeLayoutDir(path string) string {
|
||||||
if !s.hasTheme() {
|
if !s.PathSpec.ThemeSet() {
|
||||||
return ""
|
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 {
|
func (s *Site) absContentDir() string {
|
||||||
|
@ -1671,7 +1655,7 @@ func errorCollator(results <-chan error, errs chan<- error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Site) appendThemeTemplates(in []string) []string {
|
func (s *Site) appendThemeTemplates(in []string) []string {
|
||||||
if !s.hasTheme() {
|
if !s.PathSpec.ThemeSet() {
|
||||||
return in
|
return in
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1798,8 +1782,9 @@ func (s *Site) renderAndWritePage(name string, dest string, d interface{}, layou
|
||||||
}
|
}
|
||||||
|
|
||||||
transformLinks := transform.NewEmptyTransforms()
|
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)
|
transformLinks = append(transformLinks, transform.AbsURL)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1816,18 +1801,18 @@ func (s *Site) renderAndWritePage(name string, dest string, d interface{}, layou
|
||||||
|
|
||||||
var path []byte
|
var path []byte
|
||||||
|
|
||||||
if s.Cfg.GetBool("relativeURLs") {
|
if relativeURLs {
|
||||||
translated, err := pageTarget.(target.OptionalTranslator).TranslateRelative(dest)
|
translated, err := pageTarget.(target.OptionalTranslator).TranslateRelative(dest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
path = []byte(helpers.GetDottedRelativePath(translated))
|
path = []byte(helpers.GetDottedRelativePath(translated))
|
||||||
} else if s.Cfg.GetBool("canonifyURLs") {
|
} else if s.Info.canonifyURLs {
|
||||||
s := s.Cfg.GetString("baseURL")
|
url := s.Cfg.GetString("baseURL")
|
||||||
if !strings.HasSuffix(s, "/") {
|
if !strings.HasSuffix(url, "/") {
|
||||||
s += "/"
|
url += "/"
|
||||||
}
|
}
|
||||||
path = []byte(s)
|
path = []byte(url)
|
||||||
}
|
}
|
||||||
|
|
||||||
transformer := transform.NewChain(transformLinks...)
|
transformer := transform.NewChain(transformLinks...)
|
||||||
|
|
Loading…
Reference in a new issue