mirror of
https://github.com/gohugoio/hugo.git
synced 2024-12-27 03:34:02 +00:00
Make per-page url overrides take precedence over section permalink settings
This seems more reasonable to me. I didn't understand why the pUrl comparision was on len > 2; I changed it to 0. Closes #212.
This commit is contained in:
parent
732b5d42b2
commit
ea8d0981d5
2 changed files with 23 additions and 14 deletions
|
@ -235,17 +235,19 @@ func (p *Page) permalink() (*url.URL, error) {
|
|||
var permalink string
|
||||
var err error
|
||||
|
||||
if len(pUrl) > 0 {
|
||||
return helpers.MakePermalink(baseUrl, pUrl), nil
|
||||
}
|
||||
|
||||
if override, ok := p.Site.Permalinks[p.Section]; ok {
|
||||
permalink, err = override.Expand(p)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
//fmt.Printf("have an override for %q in section %s → %s\n", p.Title, p.Section, permalink)
|
||||
// fmt.Printf("have a section override for %q in section %s → %s\n", p.Title, p.Section, permalink)
|
||||
} else {
|
||||
if len(pSlug) > 0 {
|
||||
permalink = helpers.UrlPrep(p.Site.Config.UglyUrls, path.Join(dir, p.Slug+"."+p.Extension))
|
||||
} else if len(pUrl) > 2 {
|
||||
permalink = pUrl
|
||||
} else {
|
||||
_, t := path.Split(p.FileName)
|
||||
permalink = helpers.UrlPrep(p.Site.Config.UglyUrls, path.Join(dir, helpers.ReplaceExtension(strings.TrimSpace(t), p.Extension)))
|
||||
|
|
|
@ -11,26 +11,33 @@ func TestPermalink(t *testing.T) {
|
|||
dir string
|
||||
base template.URL
|
||||
slug string
|
||||
url string
|
||||
uglyurls bool
|
||||
expectedAbs string
|
||||
expectedRel string
|
||||
}{
|
||||
{"x/y/z/boofar.md", "x/y/z", "", "", false, "/x/y/z/boofar", "/x/y/z/boofar"},
|
||||
{"x/y/z/boofar.md", "x/y/z/", "", "", false, "/x/y/z/boofar", "/x/y/z/boofar"},
|
||||
{"x/y/z/boofar.md", "x/y/z/", "", "boofar", false, "/x/y/z/boofar", "/x/y/z/boofar"},
|
||||
{"x/y/z/boofar.md", "x/y/z", "http://barnew/", "", false, "http://barnew/x/y/z/boofar", "/x/y/z/boofar"},
|
||||
{"x/y/z/boofar.md", "x/y/z/", "http://barnew/", "boofar", false, "http://barnew/x/y/z/boofar", "/x/y/z/boofar"},
|
||||
{"x/y/z/boofar.md", "x/y/z", "", "", true, "/x/y/z/boofar.html", "/x/y/z/boofar.html"},
|
||||
{"x/y/z/boofar.md", "x/y/z/", "", "", true, "/x/y/z/boofar.html", "/x/y/z/boofar.html"},
|
||||
{"x/y/z/boofar.md", "x/y/z/", "", "boofar", true, "/x/y/z/boofar.html", "/x/y/z/boofar.html"},
|
||||
{"x/y/z/boofar.md", "x/y/z", "http://barnew/", "", true, "http://barnew/x/y/z/boofar.html", "/x/y/z/boofar.html"},
|
||||
{"x/y/z/boofar.md", "x/y/z/", "http://barnew/", "boofar", true, "http://barnew/x/y/z/boofar.html", "/x/y/z/boofar.html"},
|
||||
{"x/y/z/boofar.md", "x/y/z", "", "", "", false, "/x/y/z/boofar", "/x/y/z/boofar"},
|
||||
{"x/y/z/boofar.md", "x/y/z/", "", "", "", false, "/x/y/z/boofar", "/x/y/z/boofar"},
|
||||
{"x/y/z/boofar.md", "x/y/z/", "", "boofar", "", false, "/x/y/z/boofar", "/x/y/z/boofar"},
|
||||
{"x/y/z/boofar.md", "x/y/z", "http://barnew/", "", "", false, "http://barnew/x/y/z/boofar", "/x/y/z/boofar"},
|
||||
{"x/y/z/boofar.md", "x/y/z/", "http://barnew/", "boofar", "", false, "http://barnew/x/y/z/boofar", "/x/y/z/boofar"},
|
||||
{"x/y/z/boofar.md", "x/y/z", "", "", "", true, "/x/y/z/boofar.html", "/x/y/z/boofar.html"},
|
||||
{"x/y/z/boofar.md", "x/y/z/", "", "", "", true, "/x/y/z/boofar.html", "/x/y/z/boofar.html"},
|
||||
{"x/y/z/boofar.md", "x/y/z/", "", "boofar", "", true, "/x/y/z/boofar.html", "/x/y/z/boofar.html"},
|
||||
{"x/y/z/boofar.md", "x/y/z", "http://barnew/", "", "", true, "http://barnew/x/y/z/boofar.html", "/x/y/z/boofar.html"},
|
||||
{"x/y/z/boofar.md", "x/y/z/", "http://barnew/", "boofar", "", true, "http://barnew/x/y/z/boofar.html", "/x/y/z/boofar.html"},
|
||||
|
||||
// test url overrides
|
||||
{"x/y/z/boofar.md", "x/y/z", "", "", "/z/y/q/", false, "/z/y/q/", "/z/y/q/"},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
p := &Page{
|
||||
Node: Node{
|
||||
UrlPath: UrlPath{Section: "z"},
|
||||
UrlPath: UrlPath{
|
||||
Section: "z",
|
||||
Url: test.url,
|
||||
},
|
||||
Site: SiteInfo{
|
||||
BaseUrl: test.base,
|
||||
Config: &Config{
|
||||
|
|
Loading…
Reference in a new issue