diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2020-02-19 09:01:02 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2020-02-19 09:08:32 +0100 |
commit | 7489a864591b6df03f435f40696c6ceeb4776ec9 (patch) | |
tree | 00590305f79683ac9ef2ba476d649fd5ca510240 /hugolib/site_benchmark_new_test.go | |
parent | da54787cfa97789624e467a4451dfeb50f563e41 (diff) |
Add a list terms benchmark
See #6905
Diffstat (limited to 'hugolib/site_benchmark_new_test.go')
-rw-r--r-- | hugolib/site_benchmark_new_test.go | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/hugolib/site_benchmark_new_test.go b/hugolib/site_benchmark_new_test.go index 2e3842d38..4ffeaa8a1 100644 --- a/hugolib/site_benchmark_new_test.go +++ b/hugolib/site_benchmark_new_test.go @@ -375,6 +375,56 @@ contentDir="content/sv" }, }, + {"List terms", func(b testing.TB) *sitesBuilder { + + pageTemplateTemplate := ` +{{ $taxo := "categories" }} +<ul> + {{ range .Param $taxo }} + {{ $name := . }} + {{ with $.Site.GetPage (printf "/%s/%s" $taxo ($name | urlize)) }} + <li><a href="{{ .Permalink }}">{{ $name }}</a></li> + {{ end }} + {{ end }} +</ul> +` + + sb := newTestSitesBuilder(b).WithConfigFile("toml", ` +baseURL = "https://example.com" +`) + + sb.WithTemplates("_default/single.html", pageTemplateTemplate) + + r := rand.New(rand.NewSource(99)) + + createContent := func(dir, name string) { + var content string + if strings.Contains(name, "_index") { + content = pageContent(1) + } else { + content = pageContentWithCategory(1, fmt.Sprintf("category%d", r.Intn(5)+1)) + sb.WithContent(filepath.Join("content", dir, name), content) + } + } + + for level := 1; level <= r.Intn(5)+1; level++ { + sectionDir := path.Join(strings.Repeat("section/", level)) + createContent(sectionDir, "_index.md") + for i := 1; i <= r.Intn(33); i++ { + leafBundleDir := path.Join(sectionDir, fmt.Sprintf("bundle%d", i)) + createContent(leafBundleDir, "index.md") + } + } + + return sb + }, + func(s *sitesBuilder) { + s.AssertFileContent("public/section/bundle8/index.html", ` <li><a href="https://example.com/categories/category1/">category1</a></li>`) + s.Assert(len(s.H.Sites), qt.Equals, 1) + s.Assert(len(s.H.Sites[0].RegularPages()), qt.Equals, 35) + + }, + }, } return benchmarks |