mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-07 20:30:36 -05:00
Make absURL properly handle baseURL with path component
This commit is contained in:
parent
94c3825e5b
commit
0962470850
2 changed files with 13 additions and 1 deletions
|
@ -151,7 +151,17 @@ func AbsURL(path string) string {
|
|||
if strings.HasPrefix(path, "http") || strings.HasPrefix(path, "//") {
|
||||
return path
|
||||
}
|
||||
return MakePermalink(viper.GetString("BaseURL"), path).String()
|
||||
|
||||
baseURL := viper.GetString("BaseURL")
|
||||
if strings.HasPrefix(path, "/") {
|
||||
p, err := url.Parse(baseURL)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
p.Path = ""
|
||||
baseURL = p.String()
|
||||
}
|
||||
return MakePermalink(baseURL, path).String()
|
||||
}
|
||||
|
||||
// RelURL creates a URL relative to the BaseURL root.
|
||||
|
|
|
@ -53,6 +53,8 @@ func TestAbsURL(t *testing.T) {
|
|||
{"/test/2/foo/", "http://base", "http://base/test/2/foo/"},
|
||||
{"http://abs", "http://base/", "http://abs"},
|
||||
{"//schemaless", "http://base/", "//schemaless"},
|
||||
{"test/2/foo/", "http://base/path", "http://base/path/test/2/foo/"},
|
||||
{"/test/2/foo/", "http://base/path", "http://base/test/2/foo/"},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
|
|
Loading…
Reference in a new issue