URI: 
       Fix cache busting setup - hugo - [fork] hugo port for 9front
  HTML git clone git@git.drkhsh.at/hugo.git
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
   DIR README
   DIR LICENSE
       ---
   DIR commit 6bbec9001445f623cead19de6811ee960cc53a10
   DIR parent 5bd22ba85f614e0d5cc11f5eecfa4b8227d6b524
  HTML Author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
       Date:   Wed, 19 Jul 2023 15:37:17 +0200
       
       Fix cache busting setup
       
       By correctly capturing the target variable when compiling the cache buster.
       
       Fixes #11268
       
       Diffstat:
         M config/commonConfig.go              |      16 ++++++++--------
         M config/commonConfig_test.go         |      33 +++++++++++++++++++++++++++++++
       
       2 files changed, 41 insertions(+), 8 deletions(-)
       ---
   DIR diff --git a/config/commonConfig.go b/config/commonConfig.go
       @@ -333,11 +333,11 @@ func (c *CacheBuster) CompileConfig(logger loggers.Logger) error {
                }
        
                source := c.Source
       -        target := c.Target
                sourceRe, err := regexp.Compile(source)
                if err != nil {
                        return fmt.Errorf("failed to compile cache buster source %q: %w", c.Source, err)
                }
       +        target := c.Target
                var compileErr error
                debugl := logger.Logger().WithLevel(logg.LevelDebug).WithField(loggers.FieldNameCmd, "cachebuster")
        
       @@ -353,23 +353,23 @@ func (c *CacheBuster) CompileConfig(logger loggers.Logger) error {
                                return nil
                        }
                        groups := m[1:]
       +                currentTarget := target
                        // Replace $1, $2 etc. in target.
       -
                        for i, g := range groups {
       -                        target = strings.ReplaceAll(target, fmt.Sprintf("$%d", i+1), g)
       +                        currentTarget = strings.ReplaceAll(target, fmt.Sprintf("$%d", i+1), g)
                        }
       -                targetRe, err := regexp.Compile(target)
       +                targetRe, err := regexp.Compile(currentTarget)
                        if err != nil {
       -                        compileErr = fmt.Errorf("failed to compile cache buster target %q: %w", target, err)
       +                        compileErr = fmt.Errorf("failed to compile cache buster target %q: %w", currentTarget, err)
                                return nil
                        }
       -                return func(s string) bool {
       -                        match = targetRe.MatchString(s)
       +                return func(ss string) bool {
       +                        match = targetRe.MatchString(ss)
                                matchString := "no match"
                                if match {
                                        matchString = "match!"
                                }
       -                        logger.Debugf("Matching %q with target %q: %s", s, target, matchString)
       +                        logger.Debugf("Matching %q with target %q: %s", ss, currentTarget, matchString)
        
                                return match
                        }
   DIR diff --git a/config/commonConfig_test.go b/config/commonConfig_test.go
       @@ -164,3 +164,36 @@ func TestBuildConfigCacheBusters(t *testing.T) {
                c.Assert(m("json"), qt.IsTrue)
        
        }
       +
       +func TestBuildConfigCacheBusterstTailwindSetup(t *testing.T) {
       +        c := qt.New(t)
       +        cfg := New()
       +        cfg.Set("build", map[string]interface{}{
       +                "cacheBusters": []map[string]string{
       +                        {
       +                                "source": "assets/watching/hugo_stats\\.json",
       +                                "target": "css",
       +                        },
       +                        {
       +                                "source": "(postcss|tailwind)\\.config\\.js",
       +                                "target": "css",
       +                        },
       +                        {
       +                                "source": "assets/.*\\.(js|ts|jsx|tsx)",
       +                                "target": "js",
       +                        },
       +                        {
       +                                "source": "assets/.*\\.(.*)$",
       +                                "target": "$1",
       +                        },
       +                },
       +        })
       +
       +        conf := DecodeBuildConfig(cfg)
       +        l := loggers.NewDefault()
       +        c.Assert(conf.CompileConfig(l), qt.IsNil)
       +
       +        m, err := conf.MatchCacheBuster(l, "assets/watching/hugo_stats.json")
       +        c.Assert(err, qt.IsNil)
       +        c.Assert(m("css"), qt.IsTrue)
       +}