aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2020-01-30 18:35:40 +0100
committerBjørn Erik Pedersen <[email protected]>2020-01-30 23:45:19 +0100
commit2d159e9cc7a25832e4b0cad226b149f7c4624708 (patch)
tree70f3f72c916b03fd34460392dd52d8200e108e8f
parentf45cb3172862140883cfa08bd401c17e1ada5b39 (diff)
downloadhugo-2d159e9cc7a25832e4b0cad226b149f7c4624708.tar.gz
hugo-2d159e9cc7a25832e4b0cad226b149f7c4624708.zip
Do not render alias paginator pages for non-HTML outputs
Update #6797
-rw-r--r--hugolib/paginator_test.go33
-rw-r--r--hugolib/site_render.go12
2 files changed, 40 insertions, 5 deletions
diff --git a/hugolib/paginator_test.go b/hugolib/paginator_test.go
index a97a59d04..e6a196150 100644
--- a/hugolib/paginator_test.go
+++ b/hugolib/paginator_test.go
@@ -17,6 +17,8 @@ import (
"fmt"
"path/filepath"
"testing"
+
+ qt "github.com/frankban/quicktest"
)
func TestPaginator(t *testing.T) {
@@ -105,3 +107,34 @@ func TestPaginateWithSort(t *testing.T) {
b.Build(BuildCfg{}).AssertFileContent("public/index.html",
filepath.FromSlash("|content/sect/doc1.nn.md|content/sect/doc1.nb.md|content/sect/doc1.fr.md|content/sect/doc1.en.md"))
}
+
+// https://github.com/gohugoio/hugo/issues/6797
+func TestPaginateOutputFormat(t *testing.T) {
+ b := newTestSitesBuilder(t).WithSimpleConfigFile()
+ b.WithContent("_index.md", `---
+title: "Home"
+cascade:
+ outputs:
+ - JSON
+---`)
+
+ for i := 0; i < 22; i++ {
+ b.WithContent(fmt.Sprintf("p%d.md", i+1), fmt.Sprintf(`---
+title: "Page"
+weight: %d
+---`, i+1))
+ }
+
+ b.WithTemplatesAdded("index.json", `JSON: {{ .Paginator.TotalNumberOfElements }}: {{ range .Paginator.Pages }}|{{ .RelPermalink }}{{ end }}:DONE`)
+ b.Build(BuildCfg{})
+
+ b.AssertFileContent("public/index.json",
+ `JSON: 22
+|/p1/index.json|/p2/index.json|
+`)
+
+ // This looks odd, so are most bugs.
+ b.Assert(b.CheckExists("public/page/1/index.json/index.html"), qt.Equals, false)
+ b.Assert(b.CheckExists("public/page/1/index.json"), qt.Equals, false)
+ b.AssertFileContent("public/page/2/index.json", `JSON: 22: |/p11/index.json|/p12/index.json`)
+}
diff --git a/hugolib/site_render.go b/hugolib/site_render.go
index 59f265996..dd79a7264 100644
--- a/hugolib/site_render.go
+++ b/hugolib/site_render.go
@@ -205,12 +205,14 @@ func (s *Site) renderPaginator(p *pageState, templ tpl.Template) error {
panic(fmt.Sprintf("invalid paginator state for %q", p.pathOrTitle()))
}
- // Write alias for page 1
- d.Addends = fmt.Sprintf("/%s/%d", paginatePath, 1)
- targetPaths := page.CreateTargetPaths(d)
+ if f.IsHTML {
+ // Write alias for page 1
+ d.Addends = fmt.Sprintf("/%s/%d", paginatePath, 1)
+ targetPaths := page.CreateTargetPaths(d)
- if err := s.writeDestAlias(targetPaths.TargetFilename, p.Permalink(), f, nil); err != nil {
- return err
+ if err := s.writeDestAlias(targetPaths.TargetFilename, p.Permalink(), f, nil); err != nil {
+ return err
+ }
}
// Render pages for the rest