Create hugo_stats.json if it's mounted but does not exists

A common pattern for Tailwind 3 is to mount that file to get it on the server watch list.

A common pattern is also to add hugo_stats.json to .gitignore.

This has meant that the first time you start the server (no hugo_stats.json), it just doesn't work as expected.

Fixes #11264
This commit is contained in:
Bjørn Erik Pedersen 2023-07-19 10:28:56 +02:00
parent f1a061e9ed
commit 7ae62f4aa3
4 changed files with 37 additions and 4 deletions

View file

@ -664,7 +664,21 @@ func (c *collector) normalizeMounts(owner *moduleAdapter, mounts []Mount) ([]Mou
// Verify that Source exists
_, err := c.fs.Stat(sourceDir)
if err != nil {
continue
if strings.HasSuffix(sourceDir, files.FilenameHugoStatsJSON) {
// A common pattern for Tailwind 3 is to mount that file to get it on the server watch list.
// A common pattern is also to add hugo_stats.json to .gitignore.
// Create an empty file.
f, err := c.fs.Create(sourceDir)
if err != nil {
return nil, fmt.Errorf("%s: %q", errMsg, err)
}
f.Close()
} else {
continue
}
}
// Verify that target points to one of the predefined component dirs