Add cache busting config to support Tailwind 3

Fixes #10974
This commit is contained in:
Bjørn Erik Pedersen
2023-05-21 14:25:16 +02:00
parent 1292d5a26a
commit 2c3d4dfb74
12 changed files with 266 additions and 60 deletions

View File

@@ -18,6 +18,7 @@ import (
"testing"
"github.com/gohugoio/hugo/common/herrors"
"github.com/gohugoio/hugo/common/loggers"
"github.com/gohugoio/hugo/common/types"
qt "github.com/frankban/quicktest"
@@ -91,7 +92,7 @@ status = 301
s, err := DecodeServer(cfg)
c.Assert(err, qt.IsNil)
c.Assert(s.CompileConfig(), qt.IsNil)
c.Assert(s.CompileConfig(loggers.NewErrorLogger()), qt.IsNil)
c.Assert(s.MatchHeaders("/foo.jpg"), qt.DeepEquals, []types.KeyValueStr{
{Key: "X-Content-Type-Options", Value: "nosniff"},
@@ -139,3 +140,27 @@ status = 301`,
}
}
func TestBuildConfigCacheBusters(t *testing.T) {
c := qt.New(t)
cfg := New()
conf := DecodeBuildConfig(cfg)
l := loggers.NewInfoLogger()
c.Assert(conf.CompileConfig(l), qt.IsNil)
m, err := conf.MatchCacheBuster(l, "assets/foo/main.js")
c.Assert(err, qt.IsNil)
c.Assert(m, qt.IsNotNil)
c.Assert(m("scripts"), qt.IsTrue)
c.Assert(m("asdf"), qt.IsFalse)
m, _ = conf.MatchCacheBuster(l, "tailwind.config.js")
c.Assert(m("css"), qt.IsTrue)
c.Assert(m("js"), qt.IsFalse)
m, err = conf.MatchCacheBuster(l, "assets/foo.json")
c.Assert(err, qt.IsNil)
c.Assert(m, qt.IsNotNil)
c.Assert(m("json"), qt.IsTrue)
}