shithub: hugo

Download patch

ref: 3b596b85d1c8de74c212a3402108bfa34014ac21
parent: 87ca0d0cbea19dd2c0aac44dc2731e6247a82ece
author: Bjørn Erik Pedersen <[email protected]>
date: Fri Feb 5 16:30:48 EST 2016

Add renderToMemory flag

Only useful for benchmark testing as the rendered content will be ... invisible.

--- a/commands/benchmark.go
+++ b/commands/benchmark.go
@@ -34,6 +34,7 @@
 
 func init() {
 	initHugoBuilderFlags(benchmarkCmd)
+	initBenchmarkBuildingFlags(benchmarkCmd)
 
 	benchmarkCmd.Flags().StringVar(&cpuProfilefile, "cpuprofile", "", "path/filename for the CPU profile file")
 	benchmarkCmd.Flags().StringVar(&memProfilefile, "memprofile", "", "path/filename for the memory profile file")
--- a/commands/hugo.go
+++ b/commands/hugo.go
@@ -131,6 +131,7 @@
 	logging               bool
 	noTimes               bool
 	pluralizeListTitles   bool
+	renderToMemory        bool // for benchmark testing
 	preserveTaxonomyNames bool
 	uglyURLs              bool
 	verbose               bool
@@ -223,6 +224,10 @@
 
 }
 
+func initBenchmarkBuildingFlags(cmd *cobra.Command) {
+	cmd.Flags().BoolVar(&renderToMemory, "renderToMemory", false, "render to memory (only useful for benchmark testing)")
+}
+
 // init initializes flags.
 func init() {
 	hugoCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "verbose output")
@@ -231,6 +236,7 @@
 	hugoCmd.PersistentFlags().BoolVar(&verboseLog, "verboseLog", false, "verbose logging")
 
 	initHugoBuilderFlags(hugoCmd)
+	initBenchmarkBuildingFlags(hugoCmd)
 
 	hugoCmd.Flags().BoolVarP(&buildWatch, "watch", "w", false, "watch filesystem for changes and recreate as needed")
 	hugoCmdV = hugoCmd
@@ -459,6 +465,15 @@
 }
 
 func build(watches ...bool) error {
+
+	// Hugo writes the output to memory instead of the disk
+	// This is only used for benchmark testing. Cause the content is only visible
+	// in memory
+	if renderToMemory {
+		hugofs.DestinationFS = new(afero.MemMapFs)
+		// Rendering to memoryFS, publish to Root regardless of publishDir.
+		viper.Set("PublishDir", "/")
+	}
 
 	if err := copyStatic(); err != nil {
 		return fmt.Errorf("Error copying static files to %s: %s", helpers.AbsPathify(viper.GetString("PublishDir")), err)