Export MainSite var

Fixes hacdias/caddy-hugo#46
This commit is contained in:
Henrique Dias 2016-02-13 12:46:08 +00:00 committed by Bjørn Erik Pedersen
parent ce7c267140
commit ad176055d9
2 changed files with 13 additions and 11 deletions

View file

@ -14,9 +14,10 @@
package commands package commands
import ( import (
"github.com/spf13/cobra"
"os" "os"
"runtime/pprof" "runtime/pprof"
"github.com/spf13/cobra"
) )
var ( var (
@ -56,7 +57,7 @@ func benchmark(cmd *cobra.Command, args []string) error {
return err return err
} }
for i := 0; i < benchmarkTimes; i++ { for i := 0; i < benchmarkTimes; i++ {
mainSite = nil MainSite = nil
_ = buildSite() _ = buildSite()
} }
pprof.WriteHeapProfile(f) pprof.WriteHeapProfile(f)
@ -75,7 +76,7 @@ func benchmark(cmd *cobra.Command, args []string) error {
pprof.StartCPUProfile(f) pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile() defer pprof.StopCPUProfile()
for i := 0; i < benchmarkTimes; i++ { for i := 0; i < benchmarkTimes; i++ {
mainSite = nil MainSite = nil
_ = buildSite() _ = buildSite()
} }
} }

View file

@ -46,7 +46,7 @@ import (
"gopkg.in/fsnotify.v1" "gopkg.in/fsnotify.v1"
) )
var mainSite *hugolib.Site var MainSite *hugolib.Site
// userError is an error used to signal different error situations in command handling. // userError is an error used to signal different error situations in command handling.
type commandError struct { type commandError struct {
@ -648,18 +648,19 @@ func getDirList() []string {
} }
func buildSite(watching ...bool) (err error) { func buildSite(watching ...bool) (err error) {
fmt.Println("Started building site")
startTime := time.Now() startTime := time.Now()
if mainSite == nil { if MainSite == nil {
mainSite = new(hugolib.Site) MainSite = new(hugolib.Site)
} }
if len(watching) > 0 && watching[0] { if len(watching) > 0 && watching[0] {
mainSite.RunMode.Watching = true MainSite.RunMode.Watching = true
} }
err = mainSite.Build() err = MainSite.Build()
if err != nil { if err != nil {
return err return err
} }
mainSite.Stats() MainSite.Stats()
jww.FEEDBACK.Printf("in %v ms\n", int(1000*time.Since(startTime).Seconds())) jww.FEEDBACK.Printf("in %v ms\n", int(1000*time.Since(startTime).Seconds()))
return nil return nil
@ -667,11 +668,11 @@ func buildSite(watching ...bool) (err error) {
func rebuildSite(events []fsnotify.Event) error { func rebuildSite(events []fsnotify.Event) error {
startTime := time.Now() startTime := time.Now()
err := mainSite.ReBuild(events) err := MainSite.ReBuild(events)
if err != nil { if err != nil {
return err return err
} }
mainSite.Stats() MainSite.Stats()
jww.FEEDBACK.Printf("in %v ms\n", int(1000*time.Since(startTime).Seconds())) jww.FEEDBACK.Printf("in %v ms\n", int(1000*time.Since(startTime).Seconds()))
return nil return nil