diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2020-01-07 10:42:28 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2020-01-07 10:48:17 +0100 |
commit | ea05c0e8456e8dec71ffd796148355b0d8b36eb0 (patch) | |
tree | cc48e8266b111fce7cd0a7d3396f37c8ddd7819c /hugolib | |
parent | 273047b5ba19c0a9cdf22ea549b4bb52f19abdf2 (diff) |
hugolib: Add a benchmark with lots of templates
Diffstat (limited to 'hugolib')
-rw-r--r-- | hugolib/site_benchmark_new_test.go | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/hugolib/site_benchmark_new_test.go b/hugolib/site_benchmark_new_test.go index 13302300e..eb9a59828 100644 --- a/hugolib/site_benchmark_new_test.go +++ b/hugolib/site_benchmark_new_test.go @@ -270,6 +270,80 @@ contentDir="content/sv" }, }, + {"Many HTML templates", func(b testing.TB) *sitesBuilder { + + pageTemplateTemplate := ` +<!DOCTYPE html> +<html> + <head> + <meta charset="utf-8"> + <title>{{ if not .IsPage }}{{ .Title }}{{ else }}{{ printf "Site: %s" site.Title }}{{ end }}</title> + <style> + body { + margin: 3rem; + } + </style> + </head> + <body> + <div class="page">{{ .Content }}</div> + <ul> + {{ with .Pages }} + {{ range . }} + <li><a href="{{ .RelPermalink }}">{{ .LinkTitle }} {{ if not .IsNode }} (Page){{ end }}</a></li> + {{ end }} + {{ end }} + </ul> + </body> +</html> +` + + sb := newTestSitesBuilder(b).WithConfigFile("toml", ` +baseURL = "https://example.com" + +[languages] +[languages.en] +weight=1 +contentDir="content/en" +[languages.fr] +weight=2 +contentDir="content/fr" +[languages.no] +weight=3 +contentDir="content/no" +[languages.sv] +weight=4 +contentDir="content/sv" + +`) + + createContent := func(dir, name string) { + sb.WithContent(filepath.Join("content", dir, name), pageContent(1)) + } + + for _, lang := range []string{"en", "fr", "no", "sv"} { + sb.WithTemplatesAdded(fmt.Sprintf("_default/single.%s.html", lang), pageTemplateTemplate) + sb.WithTemplatesAdded(fmt.Sprintf("_default/list.%s.html", lang), pageTemplateTemplate) + + for level := 1; level <= 5; level++ { + sectionDir := path.Join(lang, strings.Repeat("section/", level)) + createContent(sectionDir, "_index.md") + for i := 1; i <= 3; i++ { + leafBundleDir := path.Join(sectionDir, fmt.Sprintf("bundle%d", i)) + createContent(leafBundleDir, "index.md") + } + } + } + + return sb + }, + func(s *sitesBuilder) { + s.CheckExists("public/blog/mybundle/index.html") + s.Assert(len(s.H.Sites), qt.Equals, 4) + s.Assert(len(s.H.Sites[0].RegularPages()), qt.Equals, len(s.H.Sites[1].RegularPages())) + s.Assert(len(s.H.Sites[0].RegularPages()), qt.Equals, 15) + + }, + }, } return benchmarks |