]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
Avoid writing to hugo_stats.json when there are no changes
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 22 May 2023 13:29:27 +0000 (15:29 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 22 May 2023 14:27:19 +0000 (16:27 +0200)
Fixes #10985

hugolib/hugo_sites_build.go

index f86d425b366d60fb29e07fb8ac1bc998787b280a..3464385d33e17cf99bf72c0e504a72622c0a43b4 100644 (file)
@@ -455,12 +455,21 @@ func (h *HugoSites) writeBuildStats() error {
                HTMLElements: *htmlElements,
        }
 
+       const hugoStatsName = "hugo_stats.json"
+
        js, err := json.MarshalIndent(stats, "", "  ")
        if err != nil {
                return err
        }
 
-       filename := filepath.Join(h.Configs.LoadingInfo.BaseConfig.WorkingDir, "hugo_stats.json")
+       filename := filepath.Join(h.Configs.LoadingInfo.BaseConfig.WorkingDir, hugoStatsName)
+
+       if existingContent, err := afero.ReadFile(hugofs.Os, filename); err == nil {
+               // Check if the content has changed.
+               if bytes.Equal(existingContent, js) {
+                       return nil
+               }
+       }
 
        // Make sure it's always written to the OS fs.
        if err := afero.WriteFile(hugofs.Os, filename, js, 0666); err != nil {