mirror of
https://github.com/filebrowser/filebrowser.git
synced 2024-06-07 23:00:43 +00:00
simplify a little bit
This commit is contained in:
parent
fe83294b14
commit
b266262c7a
23
hugo.go
23
hugo.go
@ -18,11 +18,34 @@ import (
|
||||
"github.com/hacdias/caddy-hugo/utils"
|
||||
"github.com/mholt/caddy/caddy/setup"
|
||||
"github.com/mholt/caddy/middleware"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/hugo/commands"
|
||||
)
|
||||
|
||||
// Setup configures the middleware
|
||||
func Setup(c *setup.Controller) (middleware.Middleware, error) {
|
||||
config, _ := config.ParseHugo(c)
|
||||
|
||||
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})
|
||||
}
|
||||
|
||||
utils.Run(config)
|
||||
|
||||
return func(next middleware.Handler) middleware.Handler {
|
||||
|
@ -13,7 +13,6 @@ import (
|
||||
|
||||
"github.com/hacdias/caddy-hugo/assets"
|
||||
"github.com/hacdias/caddy-hugo/config"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/hugo/commands"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
@ -167,51 +166,12 @@ func ParseComponents(r *http.Request) []string {
|
||||
|
||||
// Run is used to run the static website generator
|
||||
func Run(c *config.Config) {
|
||||
create := false
|
||||
|
||||
if _, err := os.Stat(c.Path + "config.yaml"); os.IsNotExist(err) {
|
||||
create = true
|
||||
}
|
||||
|
||||
if _, err := os.Stat(c.Path + "config.json"); os.IsNotExist(err) {
|
||||
create = true
|
||||
}
|
||||
|
||||
if _, err := os.Stat(c.Path + "config.toml"); os.IsNotExist(err) {
|
||||
create = true
|
||||
}
|
||||
|
||||
if create {
|
||||
cmd := &cobra.Command{}
|
||||
cmd.Flags().Bool("force", true, "")
|
||||
commands.NewSite(cmd, []string{c.Path})
|
||||
}
|
||||
|
||||
cwd, err := os.Getwd()
|
||||
|
||||
if err != nil {
|
||||
log.Print("Can't get working directory.")
|
||||
}
|
||||
|
||||
err = os.Chdir(c.Path)
|
||||
|
||||
if err != nil {
|
||||
log.Print("Can't get working directory.")
|
||||
}
|
||||
|
||||
viper.Reset()
|
||||
c.Args = append([]string{"--source", c.Path, "--destination", "public"}, c.Args...)
|
||||
commands.HugoCmd.ParseFlags(c.Args)
|
||||
err = commands.HugoCmd.RunE(nil, nil)
|
||||
|
||||
if err != nil {
|
||||
if err := commands.HugoCmd.RunE(nil, nil); err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
|
||||
err = os.Chdir(cwd)
|
||||
|
||||
if err != nil {
|
||||
log.Print("Can't get working directory.")
|
||||
}
|
||||
}
|
||||
|
||||
var splitCapitalizeExceptions = map[string]string{
|
||||
|
Loading…
Reference in New Issue
Block a user