hugolib: Pull all alias handling into one file

This commit is contained in:
Bjørn Erik Pedersen
2017-03-16 09:09:26 +01:00
parent ad8cea87f3
commit d76e5f36b4
4 changed files with 129 additions and 118 deletions

View File

@@ -1927,6 +1927,10 @@ func (s *Site) renderThing(d interface{}, layout string, w io.Writer) error {
}
func (s *Site) publish(path string, r io.Reader) (err error) {
return helpers.WriteToDisk(path, r, s.Fs.Destination)
}
func (s *Site) langDir() string {
if s.Language.Lang != s.Info.multilingual.DefaultLang.Lang || s.Info.defaultContentLanguageInSubdir {
return s.Language.Lang
@@ -1948,45 +1952,6 @@ func (s *Site) initSiteWriter() {
}
}
func (s *Site) writeDestAlias(path, permalink string, p *Page) (err error) {
return s.publishDestAlias(false, path, permalink, p)
}
func (s *Site) publishDestAlias(allowRoot bool, path, permalink string, p *Page) (err error) {
w := s.w
w.allowRoot = allowRoot
isXHTML := strings.HasSuffix(path, ".xhtml")
if s.Info.relativeURLs {
// convert `permalink` into URI relative to location of `path`
baseURL := helpers.SanitizeURLKeepTrailingSlash(s.Cfg.GetString("baseURL"))
if strings.HasPrefix(permalink, baseURL) {
permalink = "/" + strings.TrimPrefix(permalink, baseURL)
}
permalink, err = helpers.GetRelativePath(permalink, path)
if err != nil {
s.Log.ERROR.Println("Failed to make a RelativeURL alias:", path, "redirecting to", permalink)
}
permalink = filepath.ToSlash(permalink)
}
s.Log.DEBUG.Println("creating alias:", path, "redirecting to", permalink)
targetPath, err := w.targetPathAlias(path)
if err != nil {
return err
}
handler := newAliasHandler(s.Tmpl.Lookup("alias.html"))
aliasContent, err := handler.renderAlias(isXHTML, permalink, p)
if err != nil {
return err
}
return w.publish(targetPath, aliasContent)
}
func (s *Site) draftStats() string {
var msg string