diff options
author | Joe Mooring <joe.mooring@veriphor.com> | 2021-06-08 01:41:21 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-08 10:41:21 +0200 |
commit | 73483d0f9eb46838d41640f88cc05c1d16811dc5 (patch) | |
tree | 0c0bd410f7c4ea98f264076fe5cd3d0e50b3f750 /hugolib/embedded_templates_test.go | |
parent | 9b5debe4b820132759cfdf7bff7fe9c1ad0a6bb1 (diff) |
tpl: Add a terse pagination template variant to improve performance
These calls are equivalent:
{{ template "_internal/pagination.html" . }}
{{ template "_internal/pagination.html" (dict "page" .) }}
{{ template "_internal/pagination.html" (dict "page" . "format" "default") }}
To use an alternate format:
{{ template "_internal/pagination.html" (dict "page" . "format" "terse") }}
Fixes #8599
Diffstat (limited to 'hugolib/embedded_templates_test.go')
-rw-r--r-- | hugolib/embedded_templates_test.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/hugolib/embedded_templates_test.go b/hugolib/embedded_templates_test.go index c62d59b1d..5d7d6dc23 100644 --- a/hugolib/embedded_templates_test.go +++ b/hugolib/embedded_templates_test.go @@ -116,3 +116,42 @@ Disqus: // Disqus b.AssertFileContent("public/index.html", "\"disqus_shortname\" + '.disqus.com/embed.js';") } + +func TestEmbeddedPaginationTemplate(t *testing.T) { + t.Parallel() + + test := func(variant string, expectedOutput string) { + b := newTestSitesBuilder(t) + b.WithConfigFile("toml", `paginate = 1`) + b.WithContent( + "s1/p01.md", "---\ntitle: p01\n---", + "s1/p02.md", "---\ntitle: p02\n---", + "s1/p03.md", "---\ntitle: p03\n---", + "s1/p04.md", "---\ntitle: p04\n---", + "s1/p05.md", "---\ntitle: p05\n---", + "s1/p06.md", "---\ntitle: p06\n---", + "s1/p07.md", "---\ntitle: p07\n---", + "s1/p08.md", "---\ntitle: p08\n---", + "s1/p09.md", "---\ntitle: p09\n---", + "s1/p10.md", "---\ntitle: p10\n---", + ) + b.WithTemplates("index.html", `{{ .Paginate (where site.RegularPages "Section" "s1") }}`+variant) + b.Build(BuildCfg{}) + b.AssertFileContent("public/index.html", expectedOutput) + } + + expectedOutputDefaultFormat := "Pager 1\n <ul class=\"pagination pagination-default\">\n <li class=\"page-item disabled\">\n <a href=\"#\" aria-disabled=\"true\" aria-label=\"First\" class=\"page-link\" role=\"button\"><span aria-hidden=\"true\">««</span></a>\n </li>\n <li class=\"page-item disabled\">\n <a href=\"#\" aria-disabled=\"true\" aria-label=\"Previous\" class=\"page-link\" role=\"button\"><span aria-hidden=\"true\">«</span></a>\n </li>\n <li class=\"page-item active\">\n <a href=\"#\" aria-current=\"page\" aria-label=\"Page 1\" class=\"page-link\" role=\"button\">1</a>\n </li>\n <li class=\"page-item\">\n <a href=\"/page/2/\" aria-label=\"Page 2\" class=\"page-link\" role=\"button\">2</a>\n </li>\n <li class=\"page-item\">\n <a href=\"/page/3/\" aria-label=\"Page 3\" class=\"page-link\" role=\"button\">3</a>\n </li>\n <li class=\"page-item\">\n <a href=\"/page/4/\" aria-label=\"Page 4\" class=\"page-link\" role=\"button\">4</a>\n </li>\n <li class=\"page-item\">\n <a href=\"/page/5/\" aria-label=\"Page 5\" class=\"page-link\" role=\"button\">5</a>\n </li>\n <li class=\"page-item\">\n <a href=\"/page/2/\" aria-label=\"Next\" class=\"page-link\" role=\"button\"><span aria-hidden=\"true\">»</span></a>\n </li>\n <li class=\"page-item\">\n <a href=\"/page/10/\" aria-label=\"Last\" class=\"page-link\" role=\"button\"><span aria-hidden=\"true\">»»</span></a>\n </li>\n </ul>" + expectedOutputTerseFormat := "Pager 1\n <ul class=\"pagination pagination-terse\">\n <li class=\"page-item active\">\n <a href=\"#\" aria-current=\"page\" aria-label=\"Page 1\" class=\"page-link\" role=\"button\">1</a>\n </li>\n <li class=\"page-item\">\n <a href=\"/page/2/\" aria-label=\"Page 2\" class=\"page-link\" role=\"button\">2</a>\n </li>\n <li class=\"page-item\">\n <a href=\"/page/3/\" aria-label=\"Page 3\" class=\"page-link\" role=\"button\">3</a>\n </li>\n <li class=\"page-item\">\n <a href=\"/page/2/\" aria-label=\"Next\" class=\"page-link\" role=\"button\"><span aria-hidden=\"true\">»</span></a>\n </li>\n <li class=\"page-item\">\n <a href=\"/page/10/\" aria-label=\"Last\" class=\"page-link\" role=\"button\"><span aria-hidden=\"true\">»»</span></a>\n </li>\n </ul>" + + variant := `{{ template "_internal/pagination.html" . }}` + test(variant, expectedOutputDefaultFormat) + + variant = `{{ template "_internal/pagination.html" (dict "page" .) }}` + test(variant, expectedOutputDefaultFormat) + + variant = `{{ template "_internal/pagination.html" (dict "page" . "format" "default") }}` + test(variant, expectedOutputDefaultFormat) + + variant = `{{ template "_internal/pagination.html" (dict "page" . "format" "terse") }}` + test(variant, expectedOutputTerseFormat) +} |