mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-07 20:30:36 -05:00
Avoid writing to hugo_stats.json when there are no changes
Fixes #10985
This commit is contained in:
parent
2c3d4dfb74
commit
4cac5f5e30
1 changed files with 10 additions and 1 deletions
|
@ -455,12 +455,21 @@ func (h *HugoSites) writeBuildStats() error {
|
||||||
HTMLElements: *htmlElements,
|
HTMLElements: *htmlElements,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const hugoStatsName = "hugo_stats.json"
|
||||||
|
|
||||||
js, err := json.MarshalIndent(stats, "", " ")
|
js, err := json.MarshalIndent(stats, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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.
|
// Make sure it's always written to the OS fs.
|
||||||
if err := afero.WriteFile(hugofs.Os, filename, js, 0666); err != nil {
|
if err := afero.WriteFile(hugofs.Os, filename, js, 0666); err != nil {
|
||||||
|
|
Loading…
Reference in a new issue