@@ -27,6 +27,7 @@ import (
2727type siteBuildingBenchmarkConfig struct {
2828 Frontmatter string
2929 NumPages int
30+ NumLangs int
3031 RootSections int
3132 Render bool
3233 Shortcodes bool
@@ -39,6 +40,8 @@ func (s siteBuildingBenchmarkConfig) String() string {
3940 // To make it a short as possible, we only shows bools when enabled and ints when >= 0 (RootSections > 1)
4041 sep := ","
4142 id := s .Frontmatter + sep
43+ id += fmt .Sprintf ("num_langs=%d%s" , s .NumLangs , sep )
44+
4245 if s .RootSections > 1 {
4346 id += fmt .Sprintf ("num_root_sections=%d%s" , s .RootSections , sep )
4447 }
@@ -61,9 +64,10 @@ func (s siteBuildingBenchmarkConfig) String() string {
6164 }
6265
6366 return strings .TrimSuffix (id , sep )
64-
6567}
6668
69+ var someLangs = []string {"en" , "fr" , "nn" }
70+
6771func BenchmarkSiteBuilding (b * testing.B ) {
6872 var (
6973 // The below represents the full matrix of benchmarks. Big!
@@ -74,6 +78,7 @@ func BenchmarkSiteBuilding(b *testing.B) {
7478 allNumPages = []int {1 , 10 , 100 , 500 , 1000 , 5000 , 10000 }
7579 allDoRender = []bool {false , true }
7680 allDoShortCodes = []bool {false , true }
81+ allNumLangs = []int {1 , 3 }
7782 )
7883
7984 var runDefault bool
@@ -99,21 +104,24 @@ func BenchmarkSiteBuilding(b *testing.B) {
99104 }
100105
101106 var conf siteBuildingBenchmarkConfig
102- for _ , frontmatter := range allFrontmatters {
103- conf .Frontmatter = frontmatter
104- for _ , rootSections := range allNumRootSections {
105- conf .RootSections = rootSections
106- for _ , numTags := range allNumTags {
107- conf .NumTags = numTags
108- for _ , tagsPerPage := range allTagsPerPage {
109- conf .TagsPerPage = tagsPerPage
110- for _ , numPages := range allNumPages {
111- conf .NumPages = numPages
112- for _ , render := range allDoRender {
113- conf .Render = render
114- for _ , shortcodes := range allDoShortCodes {
115- conf .Shortcodes = shortcodes
116- doBenchMarkSiteBuilding (conf , b )
107+ for _ , numLangs := range allNumLangs {
108+ conf .NumLangs = numLangs
109+ for _ , frontmatter := range allFrontmatters {
110+ conf .Frontmatter = frontmatter
111+ for _ , rootSections := range allNumRootSections {
112+ conf .RootSections = rootSections
113+ for _ , numTags := range allNumTags {
114+ conf .NumTags = numTags
115+ for _ , tagsPerPage := range allTagsPerPage {
116+ conf .TagsPerPage = tagsPerPage
117+ for _ , numPages := range allNumPages {
118+ conf .NumPages = numPages
119+ for _ , render := range allDoRender {
120+ conf .Render = render
121+ for _ , shortcodes := range allDoShortCodes {
122+ conf .Shortcodes = shortcodes
123+ doBenchMarkSiteBuilding (conf , b )
124+ }
117125 }
118126 }
119127 }
@@ -199,11 +207,29 @@ baseURL = "http://example.com/blog"
199207paginate = 10
200208defaultContentLanguage = "en"
201209
210+ [languages]
211+ %s
212+
202213[Taxonomies]
203214tag = "tags"
204215category = "categories"
205216`
206217
218+ langConfigTemplate := `
219+ [languages.%s]
220+ languageName = "Lang %s"
221+ weight = %d
222+ `
223+
224+ langConfig := ""
225+
226+ for i := 0 ; i < cfg .NumLangs ; i ++ {
227+ langCode := someLangs [i ]
228+ langConfig += fmt .Sprintf (langConfigTemplate , langCode , langCode , i + 1 )
229+ }
230+
231+ siteConfig = fmt .Sprintf (siteConfig , langConfig )
232+
207233 numTags := cfg .NumTags
208234
209235 if cfg .TagsPerPage > numTags {
@@ -248,37 +274,49 @@ category = "categories"
248274
249275 fs := th .Fs
250276
251- pagesPerSection := cfg .NumPages / cfg .RootSections
277+ pagesPerSection := cfg .NumPages / cfg .RootSections / cfg .NumLangs
278+ for li := 0 ; li < cfg .NumLangs ; li ++ {
279+ fileLangCodeID := ""
280+ if li > 0 {
281+ fileLangCodeID = "." + someLangs [li ] + "."
282+ }
252283
253- for i := 0 ; i < cfg .RootSections ; i ++ {
254- for j := 0 ; j < pagesPerSection ; j ++ {
255- var tagsSlice []string
284+ for i := 0 ; i < cfg .RootSections ; i ++ {
285+ for j := 0 ; j < pagesPerSection ; j ++ {
286+ var tagsSlice []string
256287
257- if numTags > 0 {
258- tagsStart := rand .Intn (numTags ) - cfg .TagsPerPage
259- if tagsStart < 0 {
260- tagsStart = 0
288+ if numTags > 0 {
289+ tagsStart := rand .Intn (numTags ) - cfg .TagsPerPage
290+ if tagsStart < 0 {
291+ tagsStart = 0
292+ }
293+ tagsSlice = tags [tagsStart : tagsStart + cfg .TagsPerPage ]
261294 }
262- tagsSlice = tags [tagsStart : tagsStart + cfg .TagsPerPage ]
263- }
264295
265- if cfg .Frontmatter == "TOML" {
266- pageTemplate = pageTemplateTOML
267- tagsStr = "[]"
268- if cfg .TagsPerPage > 0 {
269- tagsStr = strings .Replace (fmt .Sprintf ("%q" , tagsSlice ), " " , ", " , - 1 )
270- }
271- } else {
272- // YAML
273- pageTemplate = pageTemplateYAML
274- for _ , tag := range tagsSlice {
275- tagsStr += "\n - " + tag
296+ if cfg .Frontmatter == "TOML" {
297+ pageTemplate = pageTemplateTOML
298+ tagsStr = "[]"
299+ if cfg .TagsPerPage > 0 {
300+ tagsStr = strings .Replace (fmt .Sprintf ("%q" , tagsSlice ), " " , ", " , - 1 )
301+ }
302+ } else {
303+ // YAML
304+ pageTemplate = pageTemplateYAML
305+ for _ , tag := range tagsSlice {
306+ tagsStr += "\n - " + tag
307+ }
276308 }
277- }
278309
279- content := fmt .Sprintf (pageTemplate , fmt .Sprintf ("Title%d_%d" , i , j ), tagsStr , contentPagesContent [rand .Intn (3 )])
310+ content := fmt .Sprintf (pageTemplate , fmt .Sprintf ("Title%d_%d" , i , j ), tagsStr , contentPagesContent [rand .Intn (3 )])
311+
312+ contentFilename := fmt .Sprintf ("page%d%s.md" , j , fileLangCodeID )
313+
314+ writeSource (b , fs , filepath .Join ("content" , fmt .Sprintf ("sect%d" , i ), contentFilename ), content )
315+ }
280316
281- writeSource (b , fs , filepath .Join ("content" , fmt .Sprintf ("sect%d" , i ), fmt .Sprintf ("page%d.md" , j )), content )
317+ content := fmt .Sprintf (pageTemplate , fmt .Sprintf ("Section %d" , i ), "[]" , contentPagesContent [rand .Intn (3 )])
318+ indexContentFilename := fmt .Sprintf ("_index%s.md" , fileLangCodeID )
319+ writeSource (b , fs , filepath .Join ("content" , fmt .Sprintf ("sect%d" , i ), indexContentFilename ), content )
282320 }
283321 }
284322
0 commit comments