예제 #1
0
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)
	}

}
예제 #2
0
파일: hugo.go 프로젝트: nelsonsilva/hugo
func InitializeConfig() {
	Config = hugolib.SetupConfig(&CfgFile, &Source)
	Config.BuildDrafts = Draft
	Config.UglyUrls = UglyUrls
	Config.Verbose = Verbose
	if BaseUrl != "" {
		Config.BaseUrl = BaseUrl
	}
	if Destination != "" {
		Config.PublishDir = Destination
	}
}
예제 #3
0
func InitializeConfig() {
	Config = hugolib.SetupConfig(&CfgFile, &Source)

	if hugoCmdV.PersistentFlags().Lookup("build-drafts").Changed {
		Config.BuildDrafts = Draft
	}

	if hugoCmdV.PersistentFlags().Lookup("uglyurls").Changed {
		Config.UglyUrls = UglyUrls
	}

	if hugoCmdV.PersistentFlags().Lookup("verbose").Changed {
		Config.Verbose = Verbose
	}
	if BaseUrl != "" {
		Config.BaseUrl = BaseUrl
	}
	if Destination != "" {
		Config.PublishDir = Destination
	}
}
예제 #4
0
파일: main.go 프로젝트: nsabine/hugo
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)
	}

}