summaryrefslogtreecommitdiffstats
path: root/hugolib/page_permalink_test.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-03-31 12:08:15 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-04-02 10:33:15 +0200
commit5185fb065b0f8a4142c29ee3e3cd917e917280a4 (patch)
treec4aad127193563eabac21e76cfc4e8e19408b155 /hugolib/page_permalink_test.go
parent92baa14fd3f45c0917c5988235cd1a0f8692f171 (diff)
hugolib: Allow relative URLs in front matter
Before this commit you would have to do this in multilingual setups: ``` --- title: "Custom!" url: "/jp/custom/foo" --- ``` This commit allows for relative URLs, e.g: ``` --- title: "Custom!" url: "custom/foo" --- ``` Which is obviously easier and more portable. The meaning of relative may change to include more in the future (e.g. role based access). Fixes #5704
Diffstat (limited to 'hugolib/page_permalink_test.go')
-rw-r--r--hugolib/page_permalink_test.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/hugolib/page_permalink_test.go b/hugolib/page_permalink_test.go
index ed6eb11e3..9df10cd53 100644
--- a/hugolib/page_permalink_test.go
+++ b/hugolib/page_permalink_test.go
@@ -104,3 +104,43 @@ Content
}
}
+
+func TestRelativeURLInFrontMatter(t *testing.T) {
+
+ config := `
+
+defaultContentLanguage = "en"
+defaultContentLanguageInSubdir = false
+
+[Languages]
+[Languages.en]
+weight = 10
+contentDir = "content/en"
+[Languages.nn]
+weight = 20
+contentDir = "content/nn"
+
+`
+
+ pageTempl := `---
+title: "A page"
+url: %q
+---
+
+Some content.
+`
+
+ b := newTestSitesBuilder(t).WithConfigFile("toml", config)
+ b.WithContent("content/en/blog/page1.md", fmt.Sprintf(pageTempl, "myblog/p1/"))
+ b.WithContent("content/en/blog/_index.md", fmt.Sprintf(pageTempl, "this-is-my-english-blog"))
+ b.WithContent("content/nn/blog/page1.md", fmt.Sprintf(pageTempl, "myblog/p1/"))
+ b.WithContent("content/nn/blog/_index.md", fmt.Sprintf(pageTempl, "this-is-my-blog"))
+
+ b.Build(BuildCfg{})
+
+ b.AssertFileContent("public/nn/myblog/p1/index.html", "Single: A page|Hello|nn|RelPermalink: /nn/myblog/p1/|")
+ b.AssertFileContent("public/nn/this-is-my-blog/index.html", "List Page 1|A page|Hello|/nn/this-is-my-blog/|")
+ b.AssertFileContent("public/this-is-my-english-blog/index.html", "List Page 1|A page|Hello|/this-is-my-english-blog/|")
+ b.AssertFileContent("public/myblog/p1/index.html", "Single: A page|Hello|en|RelPermalink: /myblog/p1/|Permalink: /myblog/p1/|")
+
+}