Exemple #1
0
func watchChange(c *hugolib.Config, ev *fsnotify.FileEvent) {
	if strings.HasPrefix(ev.Name, c.GetAbsPath(c.StaticDir)) {
		fmt.Println("Static file changed, syncing\n")
		copyStatic(c)
	} else {
		fmt.Println("Change detected, rebuilding site\n")
		buildSite(c)
	}
}
Exemple #2
0
func serve(port string, config *hugolib.Config) {

	if config.Verbose {
		fmt.Println("Serving pages from " + config.GetAbsPath(config.PublishDir))
	}

	fmt.Println("Web Server is available at http://localhost:" + port)
	fmt.Println("Press ctrl+c to stop")
	panic(http.ListenAndServe(":"+port, http.FileServer(http.Dir(config.GetAbsPath(config.PublishDir)))))
}
Exemple #3
0
func getDirList(c *hugolib.Config) []string {
	var a []string
	walker := func(path string, fi os.FileInfo, err error) error {
		if err != nil {
			PrintErr("Walker: ", err)
			return nil
		}

		if fi.IsDir() {
			a = append(a, path)
		}
		return nil
	}

	filepath.Walk(c.GetAbsPath(c.SourceDir), walker)
	filepath.Walk(c.GetAbsPath(c.LayoutDir), walker)

	return a
}
Exemple #4
0
func copyStatic(config *hugolib.Config) error {
	// Copy Static to Destination
	return fsync.Sync(config.GetAbsPath(config.PublishDir+"/"), config.GetAbsPath(config.StaticDir+"/"))
}