Skip to content

Commit

Permalink
Avoid writing to hugo_stats.json when there are no changes
Browse files Browse the repository at this point in the history
Fixes #10985
  • Loading branch information
bep committed May 22, 2023
1 parent 2c3d4df commit 4cac5f5
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion hugolib/hugo_sites_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 4cac5f5

Please sign in to comment.