func main() { flag.Usage = usage flag.Parse() if *help { usage() } config := hugolib.SetupConfig(cfgfile, path) config.BuildDrafts = *draft if *baseUrl != "" { config.BaseUrl = *baseUrl } else if *server { config.BaseUrl = "http://localhost:" + *port } if *version { fmt.Println("Hugo Static Site Generator v0.8") } if *cpuprofile != 0 { f, err := os.Create("/tmp/hugo-cpuprofile") if err != nil { panic(err) } pprof.StartCPUProfile(f) defer pprof.StopCPUProfile() for i := 0; i < *cpuprofile; i++ { _ = buildSite(config) } } if *checkMode { site := hugolib.NewSite(config) site.Analyze() os.Exit(2) } if *watchMode { fmt.Println("Watching for changes. Press ctrl+c to stop") _ = buildSite(config) err := NewWatcher(config, *port, *server) if err != nil { fmt.Println(err) } } _ = buildSite(config) if *server { serve(*port, config) } }
func buildSite(config *hugolib.Config) *hugolib.Site { startTime := time.Now() site := hugolib.NewSite(config) site.Build() site.Stats() fmt.Printf("in %v ms\n", int(1000*time.Since(startTime).Seconds())) return site }
func buildSite(config *hugolib.Config) (site *hugolib.Site, err error) { startTime := time.Now() site = hugolib.NewSite(config) err = site.Build() if err != nil { return } site.Stats() fmt.Printf("in %v ms\n", int(1000*time.Since(startTime).Seconds())) return site, nil }
func main() { flag.Usage = usage flag.Parse() if *help { usage() } config := hugolib.SetupConfig(cfgfile, source) config.BuildDrafts = *draft config.UglyUrls = *uglyUrls config.Verbose = *verbose if *baseUrl != "" { config.BaseUrl = *baseUrl } else if *server { config.BaseUrl = "http://localhost:" + *port } if *destination != "" { config.PublishDir = *destination } if *version { fmt.Println("Hugo Static Site Generator v0.8") } if *cpuprofile != 0 { f, err := os.Create("/tmp/hugo-cpuprofile") if err != nil { panic(err) } pprof.StartCPUProfile(f) defer pprof.StopCPUProfile() for i := 0; i < *cpuprofile; i++ { _, _ = buildSite(config) } } // Copy Static to Destination first err := fsync.SyncDel(config.GetAbsPath(config.PublishDir+"/"), config.GetAbsPath(config.StaticDir+"/")) if err != nil { log.Fatalf("Error copying static files to %s: %v", config.GetAbsPath(config.PublishDir), err) } if *checkMode { site := hugolib.NewSite(config) site.Analyze() os.Exit(0) } if *watchMode { fmt.Println("Watching for changes. Press ctrl+c to stop") _, err = buildSite(config) if err != nil { fmt.Println(err) return } err := NewWatcher(config, *port, *server) if err != nil { fmt.Println(err) } } if _, err = buildSite(config); err != nil { fmt.Println(err) } if *server { serve(*port, config) } }