Fix RelPermalink() and Urls in menus vs canonifyUrls

canonifyUrls=true, RelPermalink and baseUrl with sub-path did not work.

This fixes that by adding a check for canonifyUrl=trues=true in RelPermalink().

So given

- baseUrl "http://somehost.com/sub/"
- the path "some-path/file.html"

For canonifyUrls=false RelPermalink() returns "/sub/some-path/file.html"
For canonifyUrls=true RelPermalink() returns "/some-path/file.html"

In the last case, the Url will be made absolute and clickable in a later step.

This commit also makes the menu urls defined in site config releative. To make them work with canonifying of urls, the context root is prepended if canonifying is turned off.

Fixes #519
Fixes #711
This commit is contained in:
bep
2014-12-12 20:28:28 +01:00
parent 743998306a
commit 1b42dc572a
8 changed files with 112 additions and 31 deletions

View File

@@ -106,6 +106,7 @@ type SiteInfo struct {
Permalinks PermalinkOverrides
Params map[string]interface{}
BuildDrafts bool
canonifyUrls bool
}
// SiteSocial is a place to put social details on a site level. These are the
@@ -362,6 +363,7 @@ func (s *Site) initializeSiteInfo() {
Copyright: viper.GetString("copyright"),
DisqusShortname: viper.GetString("DisqusShortname"),
BuildDrafts: viper.GetBool("BuildDrafts"),
canonifyUrls: viper.GetBool("CanonifyUrls"),
Pages: &s.Pages,
Recent: &s.Pages,
Menus: &s.Menus,
@@ -608,10 +610,16 @@ func (s *Site) getMenusFromConfig() Menus {
}
menuEntry.MarshallMap(ime)
if strings.HasPrefix(menuEntry.Url, "/") {
// make it absolute so it matches the nodes
menuEntry.Url = s.permalinkStr(menuEntry.Url)
// make it match the nodes
menuEntryUrl := menuEntry.Url
if !s.Info.canonifyUrls {
menuEntryUrl = helpers.AddContextRoot(string(s.Info.BaseUrl), menuEntryUrl)
}
menuEntry.Url = s.prepUrl(menuEntryUrl)
}
if ret[name] == nil {
ret[name] = &Menu{}
}