Add renderToMemory flag
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 5 Feb 2016 20:30:48 +0000 (21:30 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 5 Feb 2016 20:30:48 +0000 (21:30 +0100)
Only useful for benchmark testing as the rendered content will be ... invisible.

commands/benchmark.go
commands/hugo.go

index f2b7964c070586a5d2e4d66f79584398636134c6..c90f64516421278b6051fda24cac96f4f9cbc0d2 100644 (file)
@@ -34,6 +34,7 @@ creating a benchmark.`,
 
 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")
index 591101da1f5cf18b200e9a914ea02e2b9a940cea..ed32850975df6f8cd2c56edf305a9e98c84232c1 100644 (file)
@@ -131,6 +131,7 @@ var (
        logging               bool
        noTimes               bool
        pluralizeListTitles   bool
+       renderToMemory        bool // for benchmark testing
        preserveTaxonomyNames bool
        uglyURLs              bool
        verbose               bool
@@ -223,6 +224,10 @@ func initHugoBuildCommonFlags(cmd *cobra.Command) {
 
 }
 
+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 @@ func init() {
        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
@@ -460,6 +466,15 @@ func watchConfig() {
 
 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)
        }