mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
commands: Make the server flag --renderToDisk into --renderToMemory (note)
Fixes #11987
This commit is contained in:
parent
609d798e34
commit
b1163db2c8
13 changed files with 28 additions and 28 deletions
|
@ -203,9 +203,6 @@ func (r *rootCommand) ConfigFromProvider(key int32, cfg config.Provider) (*commo
|
||||||
cfg = config.New()
|
cfg = config.New()
|
||||||
}
|
}
|
||||||
|
|
||||||
if !cfg.IsSet("renderToDisk") {
|
|
||||||
cfg.Set("renderToDisk", true)
|
|
||||||
}
|
|
||||||
if !cfg.IsSet("workingDir") {
|
if !cfg.IsSet("workingDir") {
|
||||||
cfg.Set("workingDir", dir)
|
cfg.Set("workingDir", dir)
|
||||||
} else {
|
} else {
|
||||||
|
@ -239,9 +236,7 @@ func (r *rootCommand) ConfigFromProvider(key int32, cfg config.Provider) (*commo
|
||||||
|
|
||||||
sourceFs := hugofs.Os
|
sourceFs := hugofs.Os
|
||||||
var destinationFs afero.Fs
|
var destinationFs afero.Fs
|
||||||
if cfg.GetBool("renderToDisk") {
|
if cfg.GetBool("renderToMemory") {
|
||||||
destinationFs = hugofs.Os
|
|
||||||
} else {
|
|
||||||
destinationFs = afero.NewMemMapFs()
|
destinationFs = afero.NewMemMapFs()
|
||||||
if renderStaticToDisk {
|
if renderStaticToDisk {
|
||||||
// Hybrid, render dynamic content to Root.
|
// Hybrid, render dynamic content to Root.
|
||||||
|
@ -251,6 +246,8 @@ func (r *rootCommand) ConfigFromProvider(key int32, cfg config.Provider) (*commo
|
||||||
cfg.Set("publishDirDynamic", "/")
|
cfg.Set("publishDirDynamic", "/")
|
||||||
cfg.Set("publishDirStatic", "/")
|
cfg.Set("publishDirStatic", "/")
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
destinationFs = hugofs.Os
|
||||||
}
|
}
|
||||||
|
|
||||||
fs := hugofs.NewFromSourceAndDestination(sourceFs, destinationFs, cfg)
|
fs := hugofs.NewFromSourceAndDestination(sourceFs, destinationFs, cfg)
|
||||||
|
@ -498,6 +495,7 @@ Complete documentation is available at https://gohugo.io/.`
|
||||||
cmd.PersistentFlags().StringVar(&r.cfgFile, "config", "", "config file (default is hugo.yaml|json|toml)")
|
cmd.PersistentFlags().StringVar(&r.cfgFile, "config", "", "config file (default is hugo.yaml|json|toml)")
|
||||||
cmd.PersistentFlags().StringVar(&r.cfgDir, "configDir", "config", "config dir")
|
cmd.PersistentFlags().StringVar(&r.cfgDir, "configDir", "config", "config dir")
|
||||||
cmd.PersistentFlags().BoolVar(&r.quiet, "quiet", false, "build in quiet mode")
|
cmd.PersistentFlags().BoolVar(&r.quiet, "quiet", false, "build in quiet mode")
|
||||||
|
cmd.PersistentFlags().BoolVar(&r.renderToMemory, "renderToMemory", false, "render to memory (mostly useful when running the server)")
|
||||||
|
|
||||||
// Set bash-completion
|
// Set bash-completion
|
||||||
_ = cmd.PersistentFlags().SetAnnotation("config", cobra.BashCompFilenameExt, config.ValidConfigFileExtensions)
|
_ = cmd.PersistentFlags().SetAnnotation("config", cobra.BashCompFilenameExt, config.ValidConfigFileExtensions)
|
||||||
|
@ -506,7 +504,6 @@ Complete documentation is available at https://gohugo.io/.`
|
||||||
cmd.PersistentFlags().BoolVarP(&r.debug, "debug", "", false, "debug output")
|
cmd.PersistentFlags().BoolVarP(&r.debug, "debug", "", false, "debug output")
|
||||||
cmd.PersistentFlags().StringVar(&r.logLevel, "logLevel", "", "log level (debug|info|warn|error)")
|
cmd.PersistentFlags().StringVar(&r.logLevel, "logLevel", "", "log level (debug|info|warn|error)")
|
||||||
cmd.Flags().BoolVarP(&r.buildWatch, "watch", "w", false, "watch filesystem for changes and recreate as needed")
|
cmd.Flags().BoolVarP(&r.buildWatch, "watch", "w", false, "watch filesystem for changes and recreate as needed")
|
||||||
cmd.Flags().BoolVar(&r.renderToMemory, "renderToMemory", false, "render to memory (only useful for benchmark testing)")
|
|
||||||
|
|
||||||
// Configure local flags
|
// Configure local flags
|
||||||
applyLocalFlagsBuild(cmd, r)
|
applyLocalFlagsBuild(cmd, r)
|
||||||
|
|
|
@ -928,7 +928,7 @@ func (c *hugoBuilder) hugoTry() *hugolib.HugoSites {
|
||||||
|
|
||||||
func (c *hugoBuilder) loadConfig(cd *simplecobra.Commandeer, running bool) error {
|
func (c *hugoBuilder) loadConfig(cd *simplecobra.Commandeer, running bool) error {
|
||||||
cfg := config.New()
|
cfg := config.New()
|
||||||
cfg.Set("renderToDisk", (c.s == nil && !c.r.renderToMemory) || (c.s != nil && c.s.renderToDisk))
|
cfg.Set("renderToMemory", c.r.renderToMemory)
|
||||||
watch := c.r.buildWatch || (c.s != nil && c.s.serverWatch)
|
watch := c.r.buildWatch || (c.s != nil && c.s.serverWatch)
|
||||||
if c.r.environment == "" {
|
if c.r.environment == "" {
|
||||||
// We need to set the environment as early as possible because we need it to load the correct config.
|
// We need to set the environment as early as possible because we need it to load the correct config.
|
||||||
|
|
|
@ -239,12 +239,14 @@ func (f *fileServer) createEndpoint(i int) (*http.ServeMux, net.Listener, string
|
||||||
r.Printf("Environment: %q\n", f.c.hugoTry().Deps.Site.Hugo().Environment)
|
r.Printf("Environment: %q\n", f.c.hugoTry().Deps.Site.Hugo().Environment)
|
||||||
|
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
if f.c.renderToDisk {
|
mainTarget := "disk"
|
||||||
r.Println("Serving pages from disk")
|
if f.c.r.renderToMemory {
|
||||||
} else if f.c.renderStaticToDisk {
|
mainTarget = "memory"
|
||||||
r.Println("Serving pages from memory and static files from disk")
|
}
|
||||||
|
if f.c.renderStaticToDisk {
|
||||||
|
r.Printf("Serving pages from %s and static files from disk\n", mainTarget)
|
||||||
} else {
|
} else {
|
||||||
r.Println("Serving pages from memory")
|
r.Printf("Serving pages from %s\n", mainTarget)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -444,7 +446,6 @@ type serverCommand struct {
|
||||||
doLiveReload bool
|
doLiveReload bool
|
||||||
|
|
||||||
// Flags.
|
// Flags.
|
||||||
renderToDisk bool
|
|
||||||
renderStaticToDisk bool
|
renderStaticToDisk bool
|
||||||
navigateToChanged bool
|
navigateToChanged bool
|
||||||
serverAppend bool
|
serverAppend bool
|
||||||
|
@ -516,8 +517,9 @@ func (c *serverCommand) Init(cd *simplecobra.Commandeer) error {
|
||||||
cmd.Long = `Hugo provides its own webserver which builds and serves the site.
|
cmd.Long = `Hugo provides its own webserver which builds and serves the site.
|
||||||
While hugo server is high performance, it is a webserver with limited options.
|
While hugo server is high performance, it is a webserver with limited options.
|
||||||
|
|
||||||
'hugo server' will avoid writing the rendered and served content to disk,
|
'hugo server' will by default write and server files from disk, but you can
|
||||||
preferring to store it in memory.
|
render to memory by using the '--renderToMemory' flag. This can be faster
|
||||||
|
in some cases, but it will consume more memory.
|
||||||
|
|
||||||
By default hugo will also watch your files for any changes you make and
|
By default hugo will also watch your files for any changes you make and
|
||||||
automatically rebuild the site. It will then live reload any open browser pages
|
automatically rebuild the site. It will then live reload any open browser pages
|
||||||
|
@ -537,7 +539,6 @@ of a second, you will be able to save and see your changes nearly instantly.`
|
||||||
cmd.Flags().BoolVarP(&c.serverAppend, "appendPort", "", true, "append port to baseURL")
|
cmd.Flags().BoolVarP(&c.serverAppend, "appendPort", "", true, "append port to baseURL")
|
||||||
cmd.Flags().BoolVar(&c.disableLiveReload, "disableLiveReload", false, "watch without enabling live browser reload on rebuild")
|
cmd.Flags().BoolVar(&c.disableLiveReload, "disableLiveReload", false, "watch without enabling live browser reload on rebuild")
|
||||||
cmd.Flags().BoolVar(&c.navigateToChanged, "navigateToChanged", false, "navigate to changed content file on live browser reload")
|
cmd.Flags().BoolVar(&c.navigateToChanged, "navigateToChanged", false, "navigate to changed content file on live browser reload")
|
||||||
cmd.Flags().BoolVar(&c.renderToDisk, "renderToDisk", false, "serve all files from disk (default is from memory)")
|
|
||||||
cmd.Flags().BoolVar(&c.renderStaticToDisk, "renderStaticToDisk", false, "serve static files from disk and dynamic files from memory")
|
cmd.Flags().BoolVar(&c.renderStaticToDisk, "renderStaticToDisk", false, "serve static files from disk and dynamic files from memory")
|
||||||
cmd.Flags().BoolVar(&c.disableFastRender, "disableFastRender", false, "enables full re-renders on changes")
|
cmd.Flags().BoolVar(&c.disableFastRender, "disableFastRender", false, "enables full re-renders on changes")
|
||||||
cmd.Flags().BoolVar(&c.disableBrowserError, "disableBrowserError", false, "do not show build errors in the browser")
|
cmd.Flags().BoolVar(&c.disableBrowserError, "disableBrowserError", false, "do not show build errors in the browser")
|
||||||
|
@ -589,7 +590,9 @@ func (c *serverCommand) PreRun(cd, runner *simplecobra.Commandeer) error {
|
||||||
)
|
)
|
||||||
|
|
||||||
destinationFlag := cd.CobraCommand.Flags().Lookup("destination")
|
destinationFlag := cd.CobraCommand.Flags().Lookup("destination")
|
||||||
c.renderToDisk = c.renderToDisk || (destinationFlag != nil && destinationFlag.Changed)
|
if c.r.renderToMemory && (destinationFlag != nil && destinationFlag.Changed) {
|
||||||
|
return fmt.Errorf("cannot use --renderToMemory with --destination")
|
||||||
|
}
|
||||||
c.doLiveReload = !c.disableLiveReload
|
c.doLiveReload = !c.disableLiveReload
|
||||||
c.fastRenderMode = !c.disableFastRender
|
c.fastRenderMode = !c.disableFastRender
|
||||||
c.showErrorInBrowser = c.doLiveReload && !c.disableBrowserError
|
c.showErrorInBrowser = c.doLiveReload && !c.disableBrowserError
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# Test the hugo server command.
|
# Test the hugo server command.
|
||||||
|
|
||||||
# We run these tests in parallel so let Hugo decide which port to use.
|
# We run these tests in parallel so let Hugo decide which port to use.
|
||||||
hugo server --gc &
|
hugo server --renderToMemory --gc &
|
||||||
|
|
||||||
waitServer
|
waitServer
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# Test the hugo server command when editing the config file.
|
# Test the hugo server command when editing the config file.
|
||||||
|
|
||||||
# We run these tests in parallel so let Hugo decide which port to use.
|
# We run these tests in parallel so let Hugo decide which port to use.
|
||||||
hugo server &
|
hugo server --renderToMemory &
|
||||||
|
|
||||||
waitServer
|
waitServer
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
# We run these tests in parallel so let Hugo decide which port to use.
|
# We run these tests in parallel so let Hugo decide which port to use.
|
||||||
# Render to disk so we can check the /public dir.
|
# Render to disk so we can check the /public dir.
|
||||||
hugo server --renderToDisk &
|
hugo server &
|
||||||
|
|
||||||
waitServer
|
waitServer
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# Test the hugo server command.
|
# Test the hugo server command.
|
||||||
|
|
||||||
# We run these tests in parallel so let Hugo decide which port to use.
|
# We run these tests in parallel so let Hugo decide which port to use.
|
||||||
hugo server &
|
hugo server --renderToMemory &
|
||||||
|
|
||||||
waitServer
|
waitServer
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
hugo server &
|
hugo server --renderToMemory &
|
||||||
|
|
||||||
waitServer
|
waitServer
|
||||||
stopServer
|
stopServer
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
hugo server --disableLiveReload &
|
hugo server --renderToMemory --disableLiveReload &
|
||||||
|
|
||||||
waitServer
|
waitServer
|
||||||
stopServer
|
stopServer
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
hugo server --renderToDisk --disableLiveReload &
|
hugo server --disableLiveReload &
|
||||||
|
|
||||||
waitServer
|
waitServer
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
hugo server --renderToDisk &
|
hugo server &
|
||||||
|
|
||||||
waitServer
|
waitServer
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# Test the hugo server command.
|
# Test the hugo server command.
|
||||||
|
|
||||||
# We run these tests in parallel so let Hugo decide which port to use.
|
# We run these tests in parallel so let Hugo decide which port to use.
|
||||||
hugo server --renderStaticToDisk &
|
hugo server --renderToMemory --renderStaticToDisk &
|
||||||
|
|
||||||
waitServer
|
waitServer
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
# We run these tests in parallel so let Hugo decide which port to use.
|
# We run these tests in parallel so let Hugo decide which port to use.
|
||||||
# Deliberately using the alias 'serve' here.
|
# Deliberately using the alias 'serve' here.
|
||||||
hugo serve &
|
hugo serve --renderToMemory &
|
||||||
|
|
||||||
waitServer
|
waitServer
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue