mirror of
https://github.com/gohugoio/hugo.git
synced 2025-03-19 07:01:35 +00:00
hugolib: Add relativeURLs and canonifyURLs to Site
This commit is contained in:
parent
c7535b9c25
commit
9e52477d94
2 changed files with 7 additions and 7 deletions
|
@ -940,8 +940,7 @@ func (p *Page) RelPermalink() string {
|
||||||
p.relPermalinkInit.Do(func() {
|
p.relPermalinkInit.Do(func() {
|
||||||
link := p.getPermalink()
|
link := p.getPermalink()
|
||||||
|
|
||||||
if p.s.Info.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))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -249,6 +249,7 @@ type SiteInfo struct {
|
||||||
Params map[string]interface{}
|
Params map[string]interface{}
|
||||||
BuildDrafts bool
|
BuildDrafts bool
|
||||||
canonifyURLs bool
|
canonifyURLs bool
|
||||||
|
relativeURLs bool
|
||||||
preserveTaxonomyNames bool
|
preserveTaxonomyNames bool
|
||||||
Data *map[string]interface{}
|
Data *map[string]interface{}
|
||||||
|
|
||||||
|
@ -977,6 +978,7 @@ func (s *Site) initializeSiteInfo() {
|
||||||
GoogleAnalytics: lang.GetString("googleAnalytics"),
|
GoogleAnalytics: lang.GetString("googleAnalytics"),
|
||||||
BuildDrafts: s.Cfg.GetBool("buildDrafts"),
|
BuildDrafts: s.Cfg.GetBool("buildDrafts"),
|
||||||
canonifyURLs: s.Cfg.GetBool("canonifyURLs"),
|
canonifyURLs: s.Cfg.GetBool("canonifyURLs"),
|
||||||
|
relativeURLs: s.Cfg.GetBool("relativeURLs"),
|
||||||
preserveTaxonomyNames: lang.GetBool("preserveTaxonomyNames"),
|
preserveTaxonomyNames: lang.GetBool("preserveTaxonomyNames"),
|
||||||
PageCollections: s.PageCollections,
|
PageCollections: s.PageCollections,
|
||||||
Files: &s.Files,
|
Files: &s.Files,
|
||||||
|
@ -1744,7 +1746,7 @@ func (s *Site) renderAndWriteXML(name string, dest string, d interface{}, layout
|
||||||
defer bp.PutBuffer(outBuffer)
|
defer bp.PutBuffer(outBuffer)
|
||||||
|
|
||||||
var path []byte
|
var path []byte
|
||||||
if s.Cfg.GetBool("relativeURLs") {
|
if s.Info.relativeURLs {
|
||||||
path = []byte(helpers.GetDottedRelativePath(dest))
|
path = []byte(helpers.GetDottedRelativePath(dest))
|
||||||
} else {
|
} else {
|
||||||
s := s.Cfg.GetString("baseURL")
|
s := s.Cfg.GetString("baseURL")
|
||||||
|
@ -1784,9 +1786,8 @@ func (s *Site) renderAndWritePage(name string, dest string, d interface{}, layou
|
||||||
}
|
}
|
||||||
|
|
||||||
transformLinks := transform.NewEmptyTransforms()
|
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)
|
transformLinks = append(transformLinks, transform.AbsURL)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1803,7 +1804,7 @@ func (s *Site) renderAndWritePage(name string, dest string, d interface{}, layou
|
||||||
|
|
||||||
var path []byte
|
var path []byte
|
||||||
|
|
||||||
if relativeURLs {
|
if s.Info.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
|
||||||
|
@ -1982,7 +1983,7 @@ func (s *Site) writeDestAlias(path, permalink string, p *Page) (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Site) publishDestAlias(aliasPublisher target.AliasPublisher, path, permalink string, p *Page) (err error) {
|
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`
|
// convert `permalink` into URI relative to location of `path`
|
||||||
baseURL := helpers.SanitizeURLKeepTrailingSlash(s.Cfg.GetString("baseURL"))
|
baseURL := helpers.SanitizeURLKeepTrailingSlash(s.Cfg.GetString("baseURL"))
|
||||||
if strings.HasPrefix(permalink, baseURL) {
|
if strings.HasPrefix(permalink, baseURL) {
|
||||||
|
|
Loading…
Reference in a new issue