Skip to content

Commit

Permalink
Avoid escaping HTML chars inside hugo_stats.json
Browse files Browse the repository at this point in the history
Fixes #11371
  • Loading branch information
bep committed Aug 21, 2023
1 parent b653853 commit bcf7421
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 6 additions & 1 deletion hugolib/hugo_sites_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,10 +492,15 @@ func (h *HugoSites) writeBuildStats() error {
HTMLElements: *htmlElements,
}

js, err := json.MarshalIndent(stats, "", " ")
var buf bytes.Buffer
enc := json.NewEncoder(&buf)
enc.SetEscapeHTML(false)
enc.SetIndent("", " ")
err := enc.Encode(stats)
if err != nil {
return err
}
js := buf.Bytes()

filename := filepath.Join(h.Configs.LoadingInfo.BaseConfig.WorkingDir, files.FilenameHugoStatsJSON)

Expand Down
3 changes: 2 additions & 1 deletion hugolib/site_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,7 @@ minify = %t
Some text.
<div class="c d e" id="el2">Foo</div>
<div class="c d e [&>p]:text-red-600" id="el2">Foo</div>
<span class=z>FOO</span>
Expand Down Expand Up @@ -1144,6 +1144,7 @@ Some text.
"d",
"e",
"hover:text-gradient",
"[&>p]:text-red-600",
"inline-block",
"lowercase",
"pb-1",
Expand Down

0 comments on commit bcf7421

Please sign in to comment.