Example #1
0
// Setup is the init function of Caddy plugins and it configures the whole
// middleware thing.
func Setup(c *setup.Controller) (middleware.Middleware, error) {
	config, _ := config.ParseHugo(c)

	// Checks if there is an Hugo website in the path that is provided.
	// If not, a new website will be created.
	create := false

	if _, err := os.Stat(config.Path + "config.yaml"); os.IsNotExist(err) {
		create = true
	}

	if _, err := os.Stat(config.Path + "config.json"); os.IsNotExist(err) {
		create = true
	}

	if _, err := os.Stat(config.Path + "config.toml"); os.IsNotExist(err) {
		create = true
	}

	if create {
		cmd := &cobra.Command{}
		cmd.Flags().Bool("force", true, "")
		commands.NewSite(cmd, []string{config.Path})
	}

	// Generates the Hugo website for the first time the plugin is activated.
	utils.Run(config)

	return func(next middleware.Handler) middleware.Handler {
		return &CaddyHugo{Next: next, Config: config}
	}, nil
}
Example #2
0
// Setup configures the middleware
func Setup(c *setup.Controller) (middleware.Middleware, error) {
	config, _ := config.ParseHugo(c)
	utils.Run(config)

	return func(next middleware.Handler) middleware.Handler {
		return &CaddyHugo{Next: next, Config: config}
	}, nil
}