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:
Nate Finch
2014-08-22 07:59:59 -04:00
committed by spf13
parent 4b979b17cc
commit a31edb3388
5 changed files with 139 additions and 21 deletions

View File

@@ -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 {