Add renderToMemory flag

Only useful for benchmark testing as the rendered content will be ... invisible.
This commit is contained in:
Bjørn Erik Pedersen 2016-02-05 21:30:48 +01:00
parent 87ca0d0cbe
commit 3b596b85d1
2 changed files with 16 additions and 0 deletions

View file

@ -34,6 +34,7 @@ creating a benchmark.`,
func init() { func init() {
initHugoBuilderFlags(benchmarkCmd) initHugoBuilderFlags(benchmarkCmd)
initBenchmarkBuildingFlags(benchmarkCmd)
benchmarkCmd.Flags().StringVar(&cpuProfilefile, "cpuprofile", "", "path/filename for the CPU profile file") benchmarkCmd.Flags().StringVar(&cpuProfilefile, "cpuprofile", "", "path/filename for the CPU profile file")
benchmarkCmd.Flags().StringVar(&memProfilefile, "memprofile", "", "path/filename for the memory profile file") benchmarkCmd.Flags().StringVar(&memProfilefile, "memprofile", "", "path/filename for the memory profile file")

View file

@ -131,6 +131,7 @@ var (
logging bool logging bool
noTimes bool noTimes bool
pluralizeListTitles bool pluralizeListTitles bool
renderToMemory bool // for benchmark testing
preserveTaxonomyNames bool preserveTaxonomyNames bool
uglyURLs bool uglyURLs bool
verbose 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. // init initializes flags.
func init() { func init() {
hugoCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "verbose output") hugoCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "verbose output")
@ -231,6 +236,7 @@ func init() {
hugoCmd.PersistentFlags().BoolVar(&verboseLog, "verboseLog", false, "verbose logging") hugoCmd.PersistentFlags().BoolVar(&verboseLog, "verboseLog", false, "verbose logging")
initHugoBuilderFlags(hugoCmd) initHugoBuilderFlags(hugoCmd)
initBenchmarkBuildingFlags(hugoCmd)
hugoCmd.Flags().BoolVarP(&buildWatch, "watch", "w", false, "watch filesystem for changes and recreate as needed") hugoCmd.Flags().BoolVarP(&buildWatch, "watch", "w", false, "watch filesystem for changes and recreate as needed")
hugoCmdV = hugoCmd hugoCmdV = hugoCmd
@ -460,6 +466,15 @@ func watchConfig() {
func build(watches ...bool) error { 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 { if err := copyStatic(); err != nil {
return fmt.Errorf("Error copying static files to %s: %s", helpers.AbsPathify(viper.GetString("PublishDir")), err) return fmt.Errorf("Error copying static files to %s: %s", helpers.AbsPathify(viper.GetString("PublishDir")), err)
} }