diff options
author | bep <bjorn.erik.pedersen@gmail.com> | 2014-12-12 20:28:28 +0100 |
---|---|---|
committer | bep <bjorn.erik.pedersen@gmail.com> | 2015-01-23 14:13:00 +0100 |
commit | 1b42dc572a0475596ffc64f8a9e0dbf8ec823094 (patch) | |
tree | 3be943bbec8906a7c65bbf992224e0e4c15f5073 /hugolib/menu_test.go | |
parent | 743998306a02a683371caeac477501418894a8f5 (diff) |
Fix RelPermalink() and Urls in menus vs canonifyUrls
canonifyUrls=true, RelPermalink and baseUrl with sub-path did not work.
This fixes that by adding a check for canonifyUrl=trues=true in RelPermalink().
So given
- baseUrl "http://somehost.com/sub/"
- the path "some-path/file.html"
For canonifyUrls=false RelPermalink() returns "/sub/some-path/file.html"
For canonifyUrls=true RelPermalink() returns "/some-path/file.html"
In the last case, the Url will be made absolute and clickable in a later step.
This commit also makes the menu urls defined in site config releative. To make them work with canonifying of urls, the context root is prepended if canonifying is turned off.
Fixes #519
Fixes #711
Diffstat (limited to 'hugolib/menu_test.go')
-rw-r--r-- | hugolib/menu_test.go | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/hugolib/menu_test.go b/hugolib/menu_test.go index afe881a94..667105f50 100644 --- a/hugolib/menu_test.go +++ b/hugolib/menu_test.go @@ -265,18 +265,27 @@ func TestPageMenu(t *testing.T) { // issue #719 func TestMenuWithUnicodeUrls(t *testing.T) { for _, uglyUrls := range []bool{true, false} { - doTestMenuWithUnicodeUrls(t, uglyUrls) + for _, canonifyUrls := range []bool{true, false} { + doTestMenuWithUnicodeUrls(t, canonifyUrls, uglyUrls) + } } } -func doTestMenuWithUnicodeUrls(t *testing.T, uglyUrls bool) { +func doTestMenuWithUnicodeUrls(t *testing.T, canonifyUrls, uglyUrls bool) { + viper.Set("CanonifyUrls", canonifyUrls) viper.Set("UglyUrls", uglyUrls) + ts := setupMenuTests(t, MENU_PAGE_SOURCES) defer resetMenuTestState(ts) unicodeRussian := ts.findTestMenuEntryById("unicode", "unicode-russian") - expectedBase := "http://foo.local/zoo/%D0%BD%D0%BE%D0%B2%D0%BE%D1%81%D1%82%D0%B8-%D0%BF%D1%80%D0%BE%D0%B5%D0%BA%D1%82%D0%B0" + expectedBase := "/%D0%BD%D0%BE%D0%B2%D0%BE%D1%81%D1%82%D0%B8-%D0%BF%D1%80%D0%BE%D0%B5%D0%BA%D1%82%D0%B0" + + if !canonifyUrls { + expectedBase = "/zoo" + expectedBase + } + var expected string if uglyUrls { expected = expectedBase + ".html" @@ -288,6 +297,7 @@ func doTestMenuWithUnicodeUrls(t *testing.T, uglyUrls bool) { } func TestTaxonomyNodeMenu(t *testing.T) { + viper.Set("CanonifyUrls", true) ts := setupMenuTests(t, MENU_PAGE_SOURCES) defer resetMenuTestState(ts) @@ -333,7 +343,7 @@ func TestHomeNodeMenu(t *testing.T) { defer resetMenuTestState(ts) home := ts.site.newHomeNode() - homeMenuEntry := &MenuEntry{Name: home.Title, Url: string(home.Permalink)} + homeMenuEntry := &MenuEntry{Name: home.Title, Url: home.Url} for i, this := range []struct { menu string |