close #14
parent
96e4ec0baf
commit
6f972d1ae4
|
@ -4,14 +4,17 @@ This is an add-on for Caddy which wants to deliver a good UI to edit the content
|
|||
|
||||
## Add-on configuration
|
||||
|
||||
You can define, or not, the admin UI styles. It will **not** replace the default ones, it will be included after it. The path must be relative to ```public``` folder.
|
||||
|
||||
```
|
||||
hugo {
|
||||
styles [file]
|
||||
styles file
|
||||
flags flags...
|
||||
}
|
||||
```
|
||||
|
||||
+ **file** is the relative path to ```public``` folder of the admin UI styles. They will not replace the defaults, they will be added.
|
||||
|
||||
+ **flags** are the Hugo flags (those which can be set in the command line) and they must follow one of these syntaxes: ```-f=value``` and ```--flag=value```.
|
||||
|
||||
## Try it
|
||||
|
||||
### Prepare your machine
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
// Config is the add-on configuration set on Caddyfile
|
||||
type Config struct {
|
||||
Styles string
|
||||
Flags []string
|
||||
}
|
||||
|
||||
// ParseHugo parses the configuration file
|
||||
|
@ -29,9 +30,21 @@ func ParseHugo(c *setup.Controller) (*Config, error) {
|
|||
conf.Styles = strings.TrimPrefix(conf.Styles, "/")
|
||||
// Add a beginning slash to make a
|
||||
conf.Styles = "/" + conf.Styles
|
||||
case "flags":
|
||||
conf.Flags = c.RemainingArgs()
|
||||
if len(conf.Flags) == 0 {
|
||||
return conf, c.ArgErr()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
conf.parseFlags()
|
||||
return conf, nil
|
||||
}
|
||||
|
||||
func (c *Config) parseFlags() {
|
||||
for index, element := range c.Flags {
|
||||
c.Flags[index] = strings.Replace(element, "\"", "", -1)
|
||||
}
|
||||
}
|
||||
|
|
5
hugo.go
5
hugo.go
|
@ -16,13 +16,12 @@ import (
|
|||
"github.com/hacdias/caddy-hugo/utils"
|
||||
"github.com/mholt/caddy/config/setup"
|
||||
"github.com/mholt/caddy/middleware"
|
||||
"github.com/spf13/hugo/commands"
|
||||
)
|
||||
|
||||
// Setup configures the middleware
|
||||
func Setup(c *setup.Controller) (middleware.Middleware, error) {
|
||||
config, _ := config.ParseHugo(c)
|
||||
commands.Execute()
|
||||
utils.RunHugo(config)
|
||||
|
||||
return func(next middleware.Handler) middleware.Handler {
|
||||
return &CaddyHugo{Next: next, Config: config}
|
||||
|
@ -120,7 +119,7 @@ func (h CaddyHugo) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error
|
|||
// Whenever the header "X-Refenerate" is true, the website should be
|
||||
// regenerated. Used in edit and settings, for example.
|
||||
if r.Header.Get("X-Regenerate") == "true" {
|
||||
commands.Execute()
|
||||
utils.RunHugo(h.Config)
|
||||
}
|
||||
|
||||
return code, err
|
||||
|
|
|
@ -12,8 +12,16 @@ import (
|
|||
"unicode"
|
||||
|
||||
"github.com/hacdias/caddy-hugo/assets"
|
||||
"github.com/hacdias/caddy-hugo/config"
|
||||
"github.com/spf13/hugo/commands"
|
||||
)
|
||||
|
||||
// RunHugo is used to run hugo
|
||||
func RunHugo(c *config.Config) {
|
||||
commands.HugoCmd.ParseFlags(c.Flags)
|
||||
commands.HugoCmd.Run(commands.HugoCmd, make([]string, 0))
|
||||
}
|
||||
|
||||
// CopyFile is used to copy a file
|
||||
func CopyFile(old, new string) error {
|
||||
// Open the file and create a new one
|
||||
|
|
Loading…
Reference in New Issue