hugolib: Fix paginator URL for sections with URL in front matter
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 26 Feb 2018 16:45:51 +0000 (17:45 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 26 Feb 2018 16:45:51 +0000 (17:45 +0100)
Fixes #4415

hugolib/page_paths.go
hugolib/site_url_test.go

index 5f45f7adf5a1842c7d1d61ad65e5703c1e72db6d..ce8a700b1c539662e9993ab04e22cd6434200932 100644 (file)
@@ -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)
index 4839c5e634067b385d9b6846cbd7bbcc6f6c7687..671695b4d22349725422c249a650bc9abb348081 100644 (file)
@@ -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/")
+
+}