From ea8d0981d5c0c820f543073299c56a3a3e2c44fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ask=20Bj=C3=B8rn=20Hansen?= Date: Thu, 27 Feb 2014 23:30:12 -0800 Subject: [PATCH] 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. --- hugolib/page.go | 8 +++++--- hugolib/page_permalink_test.go | 29 ++++++++++++++++++----------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/hugolib/page.go b/hugolib/page.go index a34a36572..2468db375 100644 --- a/hugolib/page.go +++ b/hugolib/page.go @@ -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))) diff --git a/hugolib/page_permalink_test.go b/hugolib/page_permalink_test.go index 6f08152a6..a4fed5b19 100644 --- a/hugolib/page_permalink_test.go +++ b/hugolib/page_permalink_test.go @@ -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{