Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2016-09-14 19:51:34 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2016-09-14 19:51:34 +0300
commitbbb11a4a0f9b4673ecba52d349e90db8c352e444 (patch)
treee9123ff453dd776576ea5f1a75a47488d9b3ca35 /hugolib
parentdd45e6d7e5406991d8df3a2f9ba4c7e5ae039c34 (diff)
Do not add lang prefix in URL when set in frontmatter
Fixes #2450
Diffstat (limited to 'hugolib')
-rw-r--r--hugolib/hugo_sites_test.go9
-rw-r--r--hugolib/page.go10
2 files changed, 17 insertions, 2 deletions
diff --git a/hugolib/hugo_sites_test.go b/hugolib/hugo_sites_test.go
index 3b5bf1cfc..52a3910a3 100644
--- a/hugolib/hugo_sites_test.go
+++ b/hugolib/hugo_sites_test.go
@@ -211,10 +211,13 @@ func doTestMultiSitesBuild(t *testing.T, configContent, configSuffix string) {
doc3 := enSite.Pages[2]
permalink, err = doc3.Permalink()
assert.NoError(t, err, "permalink call failed")
+ // Note that /superbob is a custom URL set in frontmatter.
+ // We respect that URL literally (it can be /search.json)
+ // and do no not do any language code prefixing.
assert.Equal(t, "http://example.com/blog/superbob", permalink, "invalid doc3 permalink")
- assert.Equal(t, "/en/superbob", doc3.URL(), "invalid url, was specified on doc3")
-
+ assert.Equal(t, "/superbob", doc3.URL(), "invalid url, was specified on doc3")
+ assertFileContent(t, "public/superbob/index.html", true, "doc3|Hello|en")
assert.Equal(t, doc2.Next, doc3, "doc3 should follow doc2, in .Next")
doc1fr := doc1en.Translations()[0]
@@ -230,6 +233,8 @@ func doTestMultiSitesBuild(t *testing.T, configContent, configSuffix string) {
permalink, err = doc4.Permalink()
assert.NoError(t, err, "permalink call failed")
assert.Equal(t, "http://example.com/blog/fr/sect/doc4/", permalink, "invalid doc4 permalink")
+ assert.Equal(t, "/blog/fr/sect/doc4/", doc4.URL())
+
assert.Len(t, doc4.Translations(), 0, "found translations for doc4")
doc5 := enSite.AllPages[5]
diff --git a/hugolib/page.go b/hugolib/page.go
index a76c157be..fe4cd077f 100644
--- a/hugolib/page.go
+++ b/hugolib/page.go
@@ -644,6 +644,16 @@ func (p *Page) Permalink() (string, error) {
return link.String(), nil
}
+func (p *Page) URL() string {
+ if p.URLPath.URL != "" {
+ // This is the url set in front matter
+ return p.URLPath.URL
+ }
+ // Fall back to the relative permalink.
+ u, _ := p.RelPermalink()
+ return u
+}
+
func (p *Page) RelPermalink() (string, error) {
link, err := p.permalink()
if err != nil {