mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-30 01:13:35 -05:00
hugolib: Fix handling of zero-length files
This was a regression in Hugo 0.20. This commit makes sure that zeron-length files are not rendered to file. Fixes #3355
This commit is contained in:
parent
e98f885b8a
commit
0e87b18b66
4 changed files with 28 additions and 0 deletions
|
@ -1939,6 +1939,10 @@ func (s *Site) renderAndWritePage(name string, dest string, p *PageOutput, layou
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if renderBuffer.Len() == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
outBuffer := bp.GetBuffer()
|
outBuffer := bp.GetBuffer()
|
||||||
defer bp.PutBuffer(outBuffer)
|
defer bp.PutBuffer(outBuffer)
|
||||||
|
|
||||||
|
|
|
@ -340,6 +340,10 @@ func (s *Site) renderRobotsTXT() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if outBuffer.Len() == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
return s.publish("robots.txt", outBuffer)
|
return s.publish("robots.txt", outBuffer)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -376,6 +376,20 @@ func TestNewSiteDefaultLang(t *testing.T) {
|
||||||
require.Equal(t, hugofs.Os, s.Fs.Destination)
|
require.Equal(t, hugofs.Os, s.Fs.Destination)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Issue #3355
|
||||||
|
func TestShouldNotWriteZeroLengthFilesToDestination(t *testing.T) {
|
||||||
|
cfg, fs := newTestCfg()
|
||||||
|
|
||||||
|
writeSource(t, fs, filepath.Join("content", "simple.html"), "simple")
|
||||||
|
writeSource(t, fs, filepath.Join("layouts", "_default/single.html"), "{{.Content}}")
|
||||||
|
writeSource(t, fs, filepath.Join("layouts", "_default/list.html"), "")
|
||||||
|
|
||||||
|
s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{})
|
||||||
|
th := testHelper{s.Cfg, s.Fs, t}
|
||||||
|
|
||||||
|
th.assertFileNotExist(filepath.Join("public", "index.html"))
|
||||||
|
}
|
||||||
|
|
||||||
// Issue #1176
|
// Issue #1176
|
||||||
func TestSectionNaming(t *testing.T) {
|
func TestSectionNaming(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
|
@ -61,6 +61,12 @@ func (th testHelper) assertFileContentRegexp(filename string, matches ...string)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (th testHelper) assertFileNotExist(filename string) {
|
||||||
|
exists, err := helpers.Exists(filename, th.Fs.Destination)
|
||||||
|
require.NoError(th.T, err)
|
||||||
|
require.False(th.T, exists)
|
||||||
|
}
|
||||||
|
|
||||||
func (th testHelper) replaceDefaultContentLanguageValue(value string) string {
|
func (th testHelper) replaceDefaultContentLanguageValue(value string) string {
|
||||||
defaultInSubDir := th.Cfg.GetBool("defaultContentLanguageInSubDir")
|
defaultInSubDir := th.Cfg.GetBool("defaultContentLanguageInSubDir")
|
||||||
replace := th.Cfg.GetString("defaultContentLanguage") + "/"
|
replace := th.Cfg.GetString("defaultContentLanguage") + "/"
|
||||||
|
|
Loading…
Reference in a new issue