shithub: hugo

Download patch

ref: 9e52477d94f56364fbdfa1a70692429eb05d7242
parent: c7535b9c259804bba3c9a6114f42e4ffb3373eec
author: bogem <[email protected]>
date: Mon Feb 20 08:52:06 EST 2017

hugolib: Add relativeURLs and canonifyURLs to Site

--- a/hugolib/page.go
+++ b/hugolib/page.go
@@ -940,8 +940,7 @@
 	p.relPermalinkInit.Do(func() {
 		link := p.getPermalink()
 
-		if p.s.Info.canonifyURLs {
-			// replacements for relpermalink with baseURL on the form http://myhost.com/sub/ will fail later on
+		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))
 			if err != nil {
--- a/hugolib/site.go
+++ b/hugolib/site.go
@@ -249,6 +249,7 @@
 	Params                map[string]interface{}
 	BuildDrafts           bool
 	canonifyURLs          bool
+	relativeURLs          bool
 	preserveTaxonomyNames bool
 	Data                  *map[string]interface{}
 
@@ -977,6 +978,7 @@
 		GoogleAnalytics:                lang.GetString("googleAnalytics"),
 		BuildDrafts:                    s.Cfg.GetBool("buildDrafts"),
 		canonifyURLs:                   s.Cfg.GetBool("canonifyURLs"),
+		relativeURLs:                   s.Cfg.GetBool("relativeURLs"),
 		preserveTaxonomyNames:          lang.GetBool("preserveTaxonomyNames"),
 		PageCollections:                s.PageCollections,
 		Files:                          &s.Files,
@@ -1744,7 +1746,7 @@
 	defer bp.PutBuffer(outBuffer)
 
 	var path []byte
-	if s.Cfg.GetBool("relativeURLs") {
+	if s.Info.relativeURLs {
 		path = []byte(helpers.GetDottedRelativePath(dest))
 	} else {
 		s := s.Cfg.GetString("baseURL")
@@ -1784,9 +1786,8 @@
 	}
 
 	transformLinks := transform.NewEmptyTransforms()
-	relativeURLs := s.Cfg.GetBool("relativeURLs")
 
-	if relativeURLs || s.Info.canonifyURLs {
+	if s.Info.relativeURLs || s.Info.canonifyURLs {
 		transformLinks = append(transformLinks, transform.AbsURL)
 	}
 
@@ -1803,7 +1804,7 @@
 
 	var path []byte
 
-	if relativeURLs {
+	if s.Info.relativeURLs {
 		translated, err := pageTarget.(target.OptionalTranslator).TranslateRelative(dest)
 		if err != nil {
 			return err
@@ -1982,7 +1983,7 @@
 }
 
 func (s *Site) publishDestAlias(aliasPublisher target.AliasPublisher, path, permalink string, p *Page) (err error) {
-	if s.Cfg.GetBool("relativeURLs") {
+	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) {