Allow rendering static files to disk and dynamic to memory in server mode

Updates #9625
This commit is contained in:
SatowTakeshi
2021-04-18 16:13:00 +09:00
committed by Bjørn Erik Pedersen
parent b9a1be2f99
commit 7d8011ed63
8 changed files with 69 additions and 25 deletions

View File

@@ -92,6 +92,7 @@ type commandeer struct {
languagesConfigured bool
languages langs.Languages
doLiveReload bool
renderStaticToDisk bool
fastRenderMode bool
showErrorInBrowser bool
wasError bool
@@ -368,8 +369,9 @@ func (c *commandeer) loadConfig() error {
}
createMemFs := config.GetBool("renderToMemory")
c.renderStaticToDisk = config.GetBool("renderStaticToDisk")
if createMemFs {
if createMemFs && !c.renderStaticToDisk {
// Rendering to memoryFS, publish to Root regardless of publishDir.
config.Set("publishDir", "/")
}
@@ -380,6 +382,14 @@ func (c *commandeer) loadConfig() error {
if c.destinationFs != nil {
// Need to reuse the destination on server rebuilds.
fs.Destination = c.destinationFs
} else if createMemFs && c.renderStaticToDisk {
// Writes the dynamic output on memory,
// while serve others directly from publishDir
publishDir := config.GetString("publishDir")
writableFs := afero.NewBasePathFs(afero.NewMemMapFs(), publishDir)
publicFs := afero.NewOsFs()
fs.Destination = afero.NewCopyOnWriteFs(afero.NewReadOnlyFs(publicFs), writableFs)
fs.DestinationStatic = publicFs
} else if createMemFs {
// Hugo writes the output to memory instead of the disk.
fs.Destination = new(afero.MemMapFs)
@@ -397,11 +407,13 @@ func (c *commandeer) loadConfig() error {
changeDetector.PrepareNew()
fs.Destination = hugofs.NewHashingFs(fs.Destination, changeDetector)
fs.DestinationStatic = hugofs.NewHashingFs(fs.DestinationStatic, changeDetector)
c.changeDetector = changeDetector
}
if c.Cfg.GetBool("logPathWarnings") {
fs.Destination = hugofs.NewCreateCountingFs(fs.Destination)
fs.DestinationStatic = hugofs.NewCreateCountingFs(fs.DestinationStatic)
}
// To debug hard-to-find path issues.