mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-14 20:33:59 +02:00
Support subdir in baseurl.
Mainly this was a change to helpers.MakePermalink, but to get the local server to run correctly, we needed to redirect the path of the request from /foo to /. In addition, I added tests for the server's code for fixing up the base url with different config file & CLI options.
This commit is contained in:
@@ -14,8 +14,10 @@
|
||||
package helpers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/PuerkitoBio/purell"
|
||||
)
|
||||
@@ -57,11 +59,23 @@ func MakePermalink(host, plink string) *url.URL {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
path, err := url.Parse(plink)
|
||||
p, err := url.Parse(plink)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return base.ResolveReference(path)
|
||||
|
||||
if p.Host != "" {
|
||||
panic(fmt.Errorf("Can't make permalink from absolute link %q", plink))
|
||||
}
|
||||
|
||||
base.Path = path.Join(base.Path, p.Path)
|
||||
|
||||
// path.Join will strip off the last /, so put it back if it was there.
|
||||
if strings.HasSuffix(p.Path, "/") && !strings.HasSuffix(base.Path, "/") {
|
||||
base.Path = base.Path + "/"
|
||||
}
|
||||
|
||||
return base
|
||||
}
|
||||
|
||||
func UrlPrep(ugly bool, in string) string {
|
||||
|
Reference in New Issue
Block a user