summaryrefslogtreecommitdiffstats
path: root/hugolib
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-02-26 17:45:51 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-02-26 17:45:51 +0100
commit9f740b37cfb3278e34a5d085380ccd4d619dabff (patch)
tree7e9ca882e5c202725e031bdd98b1b252a6a3819f /hugolib
parente39797fa720829dafd165aa25bfc2605700c38dc (diff)
hugolib: Fix paginator URL for sections with URL in front matter
Fixes #4415
Diffstat (limited to 'hugolib')
-rw-r--r--hugolib/page_paths.go6
-rw-r--r--hugolib/site_url_test.go56
2 files changed, 61 insertions, 1 deletions
diff --git a/hugolib/page_paths.go b/hugolib/page_paths.go
index 5f45f7adf..ce8a700b1 100644
--- a/hugolib/page_paths.go
+++ b/hugolib/page_paths.go
@@ -208,11 +208,15 @@ func createTargetPath(d targetPathDescriptor) string {
} else {
pagePath = filepath.Join(pagePath, d.URL)
}
+
if d.Addends != "" {
pagePath = filepath.Join(pagePath, d.Addends)
- } else if strings.HasSuffix(d.URL, "/") || !strings.Contains(d.URL, ".") {
+ }
+
+ if strings.HasSuffix(d.URL, "/") || !strings.Contains(d.URL, ".") {
pagePath = filepath.Join(pagePath, d.Type.BaseName+d.Type.MediaType.FullSuffix())
}
+
} else if d.Kind == KindPage {
if d.ExpandedPermalink != "" {
pagePath = filepath.Join(pagePath, d.ExpandedPermalink)
diff --git a/hugolib/site_url_test.go b/hugolib/site_url_test.go
index 4839c5e63..671695b4d 100644
--- a/hugolib/site_url_test.go
+++ b/hugolib/site_url_test.go
@@ -14,6 +14,7 @@
package hugolib
import (
+ "fmt"
"path/filepath"
"testing"
@@ -124,3 +125,58 @@ Do not go gentle into that good night.
assert.NotNil(ugly)
assert.Equal("/sect2/p2.html", ugly.RelPermalink())
}
+
+func TestSectionWithURLInFrontMatter(t *testing.T) {
+ t.Parallel()
+
+ assert := require.New(t)
+
+ const st = `---
+title: Do not go gentle into that good night
+url: %s
+---
+
+Wild men who caught and sang the sun in flight,
+And learn, too late, they grieved it on its way,
+Do not go gentle into that good night.
+
+`
+
+ const pt = `---
+title: Wild men who caught and sang the sun in flight
+---
+
+Wild men who caught and sang the sun in flight,
+And learn, too late, they grieved it on its way,
+Do not go gentle into that good night.
+
+`
+
+ cfg, fs := newTestCfg()
+ th := testHelper{cfg, fs, t}
+
+ cfg.Set("paginate", 1)
+
+ writeSource(t, fs, filepath.Join("content", "sect1", "_index.md"), fmt.Sprintf(st, "/ss1/"))
+ writeSource(t, fs, filepath.Join("content", "sect2", "_index.md"), fmt.Sprintf(st, "/ss2/"))
+
+ for i := 0; i < 5; i++ {
+ writeSource(t, fs, filepath.Join("content", "sect1", fmt.Sprintf("p%d.md", i+1)), pt)
+ writeSource(t, fs, filepath.Join("content", "sect2", fmt.Sprintf("p%d.md", i+1)), pt)
+ }
+
+ writeSource(t, fs, filepath.Join("layouts", "_default", "single.html"), "<html><body>{{.Content}}</body></html>")
+ writeSource(t, fs, filepath.Join("layouts", "_default", "list.html"),
+ "<html><body>P{{.Paginator.PageNumber}}|URL: {{.Paginator.URL}}|{{ if .Paginator.HasNext }}Next: {{.Paginator.Next.URL }}{{ end }}</body></html>")
+
+ s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{})
+
+ assert.Len(s.RegularPages, 10)
+
+ sect1 := s.getPage(KindSection, "sect1")
+ assert.NotNil(sect1)
+ assert.Equal("/ss1/", sect1.RelPermalink())
+ th.assertFileContent(filepath.Join("public", "ss1", "index.html"), "P1|URL: /ss1/|Next: /ss1/page/2/")
+ th.assertFileContent(filepath.Join("public", "ss1", "page", "2", "index.html"), "P2|URL: /ss1/page/2/|Next: /ss1/page/3/")
+
+}