hugo

Unnamed repository; edit this file 'description' to name the repository.

git clone git://git.shimmy1996.com/hugo.git
commit 43338c3a99769eb7d0df0c12559b8b3d42b67dba
parent dea71670c059ab4d5a42bd22503f18c087dd22d4
Author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Date:   Fri,  6 Jul 2018 13:33:43 +0200

hugolib: Do not create paginator pages for the other output formats

This is a recent regression in Hugo, where we have started to produce `/page/30/index.json` when the main output format (usually `HTML`) is set up with pagination.

For JSON this is potentially lot of superflous work and hurts performance.

This commit reinstates the earlier behaviour: We only create paginators if in use in the main output format.

And add a test for it to prevent this from happening again.

Fixes #4890

Diffstat:
Mhugolib/site_output_test.go | 14+++++++++++++-
Mhugolib/site_render.go | 3++-
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/hugolib/site_output_test.go b/hugolib/site_output_test.go
@@ -47,7 +47,7 @@ baseURL = "http://example.com/blog"
 paginate = 1
 defaultContentLanguage = "en"
 
-disableKinds = ["page", "section", "taxonomy", "taxonomyTerm", "RSS", "sitemap", "robotsTXT", "404"]
+disableKinds = ["section", "taxonomy", "taxonomyTerm", "RSS", "sitemap", "robotsTXT", "404"]
 
 [Taxonomies]
 tag = "tags"
@@ -55,6 +55,7 @@ category = "categories"
 
 defaultContentLanguage = "en"
 
+
 [languages]
 
 [languages.en]
@@ -125,8 +126,10 @@ List HTML|{{.Title }}|
 Partial Hugo 1: {{ partial "GoHugo.html" . }}
 Partial Hugo 2: {{ partial "GoHugo" . -}}
 Content: {{ .Content }}
+Len Pages: {{ .Kind }} {{ len .Site.RegularPages }} Page Number: {{ .Paginator.PageNumber }}
 {{ end }}
 `,
+		"layouts/_default/single.html", `{{ define "main" }}{{ .Content }}{{ end }}`,
 	)
 	require.Len(t, h.Sites, 2)
 
@@ -135,6 +138,11 @@ Content: {{ .Content }}
 	writeSource(t, fs, "content/_index.md", fmt.Sprintf(pageTemplate, "JSON Home", outputsStr))
 	writeSource(t, fs, "content/_index.nn.md", fmt.Sprintf(pageTemplate, "JSON Nynorsk Heim", outputsStr))
 
+	for i := 1; i <= 10; i++ {
+		writeSource(t, fs, fmt.Sprintf("content/p%d.md", i), fmt.Sprintf(pageTemplate, fmt.Sprintf("Page %d", i), outputsStr))
+
+	}
+
 	err := h.Build(BuildCfg{})
 
 	require.NoError(t, err)
@@ -175,7 +183,11 @@ Content: {{ .Content }}
 			"en: Elbow",
 			"ShortHTML",
 			"OtherShort: <h1>Hi!</h1>",
+			"Len Pages: home 10",
 		)
+		th.assertFileContent("public/page/2/index.html", "Page Number: 2")
+		th.assertFileNotExist("public/page/2/index.json")
+
 		th.assertFileContent("public/nn/index.html",
 			"List HTML|JSON Nynorsk Heim|",
 			"nn: Olboge")
diff --git a/hugolib/site_render.go b/hugolib/site_render.go
@@ -168,7 +168,8 @@ func pageRenderer(s *Site, pages <-chan *Page, results chan<- error, wg *sync.Wa
 					results <- err
 				}
 
-				if pageOutput.IsNode() {
+				// Only render paginators for the main output format
+				if i == 0 && pageOutput.IsNode() {
 					if err := s.renderPaginator(pageOutput); err != nil {
 						results <- err
 					}