mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-30 22:39:58 +02:00
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:
@@ -397,6 +397,16 @@ func (p *Page) RelPermalink() (string, error) {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if viper.GetBool("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 {
|
||||
return "", err
|
||||
}
|
||||
return "/" + filepath.ToSlash(relpath), nil
|
||||
}
|
||||
|
||||
link.Scheme = ""
|
||||
link.Host = ""
|
||||
link.User = nil
|
||||
@@ -549,7 +559,7 @@ func (page *Page) Menus() PageMenus {
|
||||
ret := PageMenus{}
|
||||
|
||||
if ms, ok := page.Params["menu"]; ok {
|
||||
link, _ := page.Permalink()
|
||||
link, _ := page.RelPermalink()
|
||||
|
||||
me := MenuEntry{Name: page.LinkTitle(), Weight: page.Weight, Url: link}
|
||||
|
||||
|
Reference in New Issue
Block a user