mirror of
https://github.com/gohugoio/hugo.git
synced 2025-03-20 13:31:06 +00:00
Hugo server renders and serves from memory by default (30%+ improvement)
This commit is contained in:
parent
e1618e9d2f
commit
df824fa31b
3 changed files with 27 additions and 6 deletions
|
@ -37,17 +37,22 @@ var serverInterface string
|
||||||
var serverWatch bool
|
var serverWatch bool
|
||||||
var serverAppend bool
|
var serverAppend bool
|
||||||
var disableLiveReload bool
|
var disableLiveReload bool
|
||||||
|
var renderToDisk bool
|
||||||
|
|
||||||
//var serverCmdV *cobra.Command
|
//var serverCmdV *cobra.Command
|
||||||
|
|
||||||
var serverCmd = &cobra.Command{
|
var serverCmd = &cobra.Command{
|
||||||
Use: "server",
|
Use: "server",
|
||||||
Short: "A high performance webserver",
|
Aliases: []string{"serve"},
|
||||||
Long: `Hugo provides its own webserver which builds and serves the site.
|
Short: "A high performance webserver",
|
||||||
|
Long: `Hugo provides it's 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.
|
||||||
Many run it in production, but the standard behavior is for people to use it in development
|
Many run it in production, but the standard behavior is for people to use it in development
|
||||||
and use a more full featured server such as Nginx or Caddy.
|
and use a more full featured server such as Nginx or Caddy.
|
||||||
|
|
||||||
|
'hugo server' will avoid writing the rendered and served content to disk,
|
||||||
|
preferring to store it in memory.
|
||||||
|
|
||||||
Often server is paired with '--watch' which Hugo will look for changes to the source and
|
Often server is paired with '--watch' which Hugo will look for changes to the source and
|
||||||
continously rebuild and serve the website.`,
|
continously rebuild and serve the website.`,
|
||||||
//Run: server,
|
//Run: server,
|
||||||
|
@ -79,6 +84,7 @@ func init() {
|
||||||
serverCmd.Flags().BoolVarP(&serverWatch, "watch", "w", false, "watch filesystem for changes and recreate as needed")
|
serverCmd.Flags().BoolVarP(&serverWatch, "watch", "w", false, "watch filesystem for changes and recreate as needed")
|
||||||
serverCmd.Flags().BoolVarP(&serverAppend, "appendPort", "", true, "append port to baseurl")
|
serverCmd.Flags().BoolVarP(&serverAppend, "appendPort", "", true, "append port to baseurl")
|
||||||
serverCmd.Flags().BoolVar(&disableLiveReload, "disableLiveReload", false, "watch without enabling live browser reload on rebuild")
|
serverCmd.Flags().BoolVar(&disableLiveReload, "disableLiveReload", false, "watch without enabling live browser reload on rebuild")
|
||||||
|
serverCmd.Flags().BoolVar(&renderToDisk, "renderToDisk", false, "render to Destination path (default is render to memory & serve from there)")
|
||||||
serverCmd.Flags().BoolVarP(&NoTimes, "noTimes", "", false, "Don't sync modification time of files")
|
serverCmd.Flags().BoolVarP(&NoTimes, "noTimes", "", false, "Don't sync modification time of files")
|
||||||
serverCmd.Flags().String("memstats", "", "log memory usage to this file")
|
serverCmd.Flags().String("memstats", "", "log memory usage to this file")
|
||||||
serverCmd.Flags().Int("meminterval", 100, "interval to poll memory usage (requires --memstats)")
|
serverCmd.Flags().Int("meminterval", 100, "interval to poll memory usage (requires --memstats)")
|
||||||
|
@ -126,6 +132,18 @@ func server(cmd *cobra.Command, args []string) {
|
||||||
jww.ERROR.Println("memstats error:", err)
|
jww.ERROR.Println("memstats error:", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If a Destination is provided via flag write to disk
|
||||||
|
if Destination != "" {
|
||||||
|
renderToDisk = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hugo writes the output to memory instead of the disk
|
||||||
|
if !renderToDisk {
|
||||||
|
hugofs.DestinationFS = new(afero.MemMapFs)
|
||||||
|
// Rendering to memoryFS, publish to Root regardless of publishDir.
|
||||||
|
viper.Set("PublishDir", "/")
|
||||||
|
}
|
||||||
|
|
||||||
build(serverWatch)
|
build(serverWatch)
|
||||||
|
|
||||||
// Watch runs its own server as part of the routine
|
// Watch runs its own server as part of the routine
|
||||||
|
@ -148,7 +166,11 @@ func server(cmd *cobra.Command, args []string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func serve(port int) {
|
func serve(port int) {
|
||||||
jww.FEEDBACK.Println("Serving pages from " + helpers.AbsPathify(viper.GetString("PublishDir")))
|
if renderToDisk {
|
||||||
|
jww.FEEDBACK.Println("Serving pages from " + helpers.AbsPathify(viper.GetString("PublishDir")))
|
||||||
|
} else {
|
||||||
|
jww.FEEDBACK.Println("Serving pages from memory")
|
||||||
|
}
|
||||||
|
|
||||||
httpFs := &afero.HttpFs{SourceFs: hugofs.DestinationFS}
|
httpFs := &afero.HttpFs{SourceFs: hugofs.DestinationFS}
|
||||||
fs := filesOnlyFs{httpFs.Dir(helpers.AbsPathify(viper.GetString("PublishDir")))}
|
fs := filesOnlyFs{httpFs.Dir(helpers.AbsPathify(viper.GetString("PublishDir")))}
|
||||||
|
|
|
@ -11,6 +11,7 @@ weight: 10
|
||||||
---
|
---
|
||||||
## **0.15.0** ???
|
## **0.15.0** ???
|
||||||
|
|
||||||
|
* `hugo server` now builds ~30%+ faster by rendering to memory instead of disk
|
||||||
* Have Jekyll site, but dreaming of porting it to Hugo? This release introduces a new `hugo import jekyll`command that makes this easier than ever. [1469](https://github.com/spf13/hugo/pull/1469)
|
* Have Jekyll site, but dreaming of porting it to Hugo? This release introduces a new `hugo import jekyll`command that makes this easier than ever. [1469](https://github.com/spf13/hugo/pull/1469)
|
||||||
* We now use a custom-built `LazyFileReader` for reading file contents, which means we don't read media files in `/content` into memory anymore -- and file reading is now performed in parallel on multicore PCs. [1181](https://github.com/spf13/hugo/issues/1181)
|
* We now use a custom-built `LazyFileReader` for reading file contents, which means we don't read media files in `/content` into memory anymore -- and file reading is now performed in parallel on multicore PCs. [1181](https://github.com/spf13/hugo/issues/1181)
|
||||||
* Hugo is now built with `Go 1.5` which, among many other improvements, have fixed the last known data race in Hugo. [917] (https://github.com/spf13/hugo/issues/917)
|
* Hugo is now built with `Go 1.5` which, among many other improvements, have fixed the last known data race in Hugo. [917] (https://github.com/spf13/hugo/issues/917)
|
||||||
|
|
|
@ -18,5 +18,3 @@ import "github.com/spf13/afero"
|
||||||
var SourceFs afero.Fs = new(afero.OsFs)
|
var SourceFs afero.Fs = new(afero.OsFs)
|
||||||
var DestinationFS afero.Fs = new(afero.OsFs)
|
var DestinationFS afero.Fs = new(afero.OsFs)
|
||||||
var OsFs afero.Fs = new(afero.OsFs)
|
var OsFs afero.Fs = new(afero.OsFs)
|
||||||
|
|
||||||
//var DestinationFS afero.Fs = new(afero.MemMapFs)
|
|
||||||
|
|
Loading…
Reference in a new issue