summaryrefslogtreecommitdiffstats
path: root/hugolib
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2023-07-01 10:37:38 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2023-07-01 15:38:32 +0200
commit11ecea610617035745e620278a309d98091f527c (patch)
tree5678f3a089542b80316f3ee1ebdb7bc3aa9197fe /hugolib
parentda98724bc8bd28532222fb379af7a3782e2a9480 (diff)
Make build.writeStats a struct
So you can do ```toml [build.writeStats] tags = true classes = true ids = false ``` Fixes #11191
Diffstat (limited to 'hugolib')
-rw-r--r--hugolib/hugo_sites_build.go2
-rw-r--r--hugolib/integrationtest_builder.go9
-rw-r--r--hugolib/site_test.go83
3 files changed, 93 insertions, 1 deletions
diff --git a/hugolib/hugo_sites_build.go b/hugolib/hugo_sites_build.go
index 9a645f3a5..2c8ca0aae 100644
--- a/hugolib/hugo_sites_build.go
+++ b/hugolib/hugo_sites_build.go
@@ -475,7 +475,7 @@ func (h *HugoSites) writeBuildStats() error {
if h.ResourceSpec == nil {
panic("h.ResourceSpec is nil")
}
- if !h.ResourceSpec.BuildConfig().WriteStats {
+ if !h.ResourceSpec.BuildConfig().WriteStats.Enabled() {
return nil
}
diff --git a/hugolib/integrationtest_builder.go b/hugolib/integrationtest_builder.go
index 3910e2b97..ada01b6ee 100644
--- a/hugolib/integrationtest_builder.go
+++ b/hugolib/integrationtest_builder.go
@@ -147,6 +147,15 @@ func (s *IntegrationTestBuilder) AssertFileContent(filename string, matches ...s
if match == "" || strings.HasPrefix(match, "#") {
continue
}
+ var negate bool
+ if strings.HasPrefix(match, "! ") {
+ negate = true
+ match = strings.TrimPrefix(match, "! ")
+ }
+ if negate {
+ s.Assert(content, qt.Not(qt.Contains), match, qt.Commentf(m))
+ continue
+ }
s.Assert(content, qt.Contains, match, qt.Commentf(m))
}
}
diff --git a/hugolib/site_test.go b/hugolib/site_test.go
index be59b17a7..8265c06d0 100644
--- a/hugolib/site_test.go
+++ b/hugolib/site_test.go
@@ -1162,6 +1162,89 @@ Some text.
}
}
+func TestClassCollectorConfigWriteStats(t *testing.T) {
+ r := func(writeStatsConfig string) *IntegrationTestBuilder {
+ files := `
+-- hugo.toml --
+WRITE_STATS_CONFIG
+-- layouts/_default/list.html --
+<div id="myid" class="myclass">Foo</div>
+
+`
+ files = strings.Replace(files, "WRITE_STATS_CONFIG", writeStatsConfig, 1)
+
+ b := NewIntegrationTestBuilder(
+ IntegrationTestConfig{
+ T: t,
+ TxtarString: files,
+ NeedsOsFS: true,
+ },
+ ).Build()
+
+ return b
+ }
+
+ // Legacy config.
+ b := r(`
+[build]
+writeStats = true
+`)
+
+ b.AssertFileContent("hugo_stats.json", "myclass", "div", "myid")
+
+ b = r(`
+[build]
+writeStats = false
+ `)
+
+ b.AssertDestinationExists("hugo_stats.json", false)
+
+ b = r(`
+[build.writeStats]
+tags = true
+classes = true
+ids = true
+ `)
+
+ b.AssertFileContent("hugo_stats.json", "myclass", "div", "myid")
+
+ b = r(`
+[build.writeStats]
+tags = true
+classes = true
+ids = false
+`)
+
+ b.AssertFileContent("hugo_stats.json", "myclass", "div", "! myid")
+
+ b = r(`
+[build.writeStats]
+tags = true
+classes = false
+ids = true
+`)
+
+ b.AssertFileContent("hugo_stats.json", "! myclass", "div", "myid")
+
+ b = r(`
+[build.writeStats]
+tags = false
+classes = true
+ids = true
+ `)
+
+ b.AssertFileContent("hugo_stats.json", "myclass", "! div", "myid")
+
+ b = r(`
+[build.writeStats]
+tags = false
+classes = false
+ids = false
+ `)
+ b.AssertDestinationExists("hugo_stats.json", false)
+
+}
+
func TestClassCollectorStress(t *testing.T) {
statsFilename := "hugo_stats.json"
defer os.Remove(statsFilename)