summaryrefslogtreecommitdiffstats
path: root/publisher
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2023-07-02 11:02:47 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2023-07-02 13:04:11 +0200
commit5afc89f2bfb3e582bface8a9980e60782ece9880 (patch)
tree325ac10ec7f26da64d7e20f11219d91428f64dba /publisher
parentc1eac616d55945c28ea364f44d1e9ae12e672e11 (diff)
Rework the build.writeStats struct
Mostly to make it easier to toggle on/off this feature from the env. See #11191
Diffstat (limited to 'publisher')
-rw-r--r--publisher/htmlElementsCollector.go12
-rw-r--r--publisher/htmlElementsCollector_test.go18
-rw-r--r--publisher/publisher.go4
3 files changed, 11 insertions, 23 deletions
diff --git a/publisher/htmlElementsCollector.go b/publisher/htmlElementsCollector.go
index 080502352..c942c46e5 100644
--- a/publisher/htmlElementsCollector.go
+++ b/publisher/htmlElementsCollector.go
@@ -47,7 +47,7 @@ var (
}
)
-func newHTMLElementsCollector(conf config.WriteStats) *htmlElementsCollector {
+func newHTMLElementsCollector(conf config.BuildStats) *htmlElementsCollector {
return &htmlElementsCollector{
conf: conf,
elementSet: make(map[string]bool),
@@ -95,7 +95,7 @@ type htmlElement struct {
}
type htmlElementsCollector struct {
- conf config.WriteStats
+ conf config.BuildStats
// Contains the raw HTML string. We will get the same element
// several times, and want to avoid costly reparsing when this
@@ -117,7 +117,7 @@ func (c *htmlElementsCollector) getHTMLElements() HTMLElements {
for _, el := range c.elements {
classes = append(classes, el.Classes...)
ids = append(ids, el.IDs...)
- if c.conf.Tags {
+ if !c.conf.DisableTags {
tags = append(tags, el.Tag)
}
}
@@ -372,7 +372,7 @@ func htmlLexToEndOfComment(w *htmlElementsCollectorWriter) htmlCollectorStateFun
func (w *htmlElementsCollectorWriter) parseHTMLElement(elStr string) (el htmlElement, err error) {
conf := w.collector.conf
- if !conf.IDs && !conf.Classes {
+ if conf.DisableTags && conf.DisableClasses {
// Nothing to do.
return
}
@@ -402,11 +402,11 @@ func (w *htmlElementsCollectorWriter) parseHTMLElement(elStr string) (el htmlEle
switch {
case strings.EqualFold(a.Key, "id"):
// There should be only one, but one never knows...
- if conf.IDs {
+ if !conf.DisableIDs {
el.IDs = append(el.IDs, a.Val)
}
default:
- if !conf.Classes {
+ if conf.DisableClasses {
continue
}
if classAttrRe.MatchString(a.Key) {
diff --git a/publisher/htmlElementsCollector_test.go b/publisher/htmlElementsCollector_test.go
index 51b34a3d6..3047d5ca9 100644
--- a/publisher/htmlElementsCollector_test.go
+++ b/publisher/htmlElementsCollector_test.go
@@ -138,11 +138,7 @@ func TestClassCollector(t *testing.T) {
c.Run(fmt.Sprintf("%s--minify-%t", test.name, variant.minify), func(c *qt.C) {
w := newHTMLElementsCollectorWriter(newHTMLElementsCollector(
- config.WriteStats{
- Tags: true,
- Classes: true,
- IDs: true,
- },
+ config.BuildStats{Enable: true},
))
if variant.minify {
if skipMinifyTest[test.name] {
@@ -248,11 +244,7 @@ func BenchmarkElementsCollectorWriter(b *testing.B) {
`
for i := 0; i < b.N; i++ {
w := newHTMLElementsCollectorWriter(newHTMLElementsCollector(
- config.WriteStats{
- Tags: true,
- Classes: true,
- IDs: true,
- },
+ config.BuildStats{Enable: true},
))
fmt.Fprint(w, benchHTML)
@@ -276,11 +268,7 @@ func BenchmarkElementsCollectorWriterPre(b *testing.B) {
`
w := newHTMLElementsCollectorWriter(newHTMLElementsCollector(
- config.WriteStats{
- Tags: true,
- Classes: true,
- IDs: true,
- },
+ config.BuildStats{Enable: true},
))
for i := 0; i < b.N; i++ {
fmt.Fprint(w, benchHTML)
diff --git a/publisher/publisher.go b/publisher/publisher.go
index 37d8b36e4..39274b2a9 100644
--- a/publisher/publisher.go
+++ b/publisher/publisher.go
@@ -81,8 +81,8 @@ func NewDestinationPublisher(rs *resources.Spec, outputFormats output.Formats, m
fs := rs.BaseFs.PublishFs
cfg := rs.Cfg
var classCollector *htmlElementsCollector
- if rs.BuildConfig().WriteStats.Enabled() {
- classCollector = newHTMLElementsCollector(rs.BuildConfig().WriteStats)
+ if rs.BuildConfig().BuildStats.Enabled() {
+ classCollector = newHTMLElementsCollector(rs.BuildConfig().BuildStats)
}
pub = DestinationPublisher{fs: fs, htmlElementsCollector: classCollector}
pub.min, err = minifiers.New(mediaTypes, outputFormats, cfg)