Remove non-hugo web gen support. See #27. Close #24

This commit is contained in:
Henrique Dias 2015-10-16 19:34:27 +01:00
parent 4ea19cab92
commit 00e9e849ea
3 changed files with 24 additions and 48 deletions

View File

@ -8,21 +8,17 @@ import (
// Config is the add-on configuration set on Caddyfile
type Config struct {
Public string
Content string
Path string
Styles string
Command string
Hugo bool
Public string // Public content path
Path string // Hugo files path
Styles string // Admin styles path
Args []string // Hugo arguments
}
// ParseCMS parses the configuration file
func ParseCMS(c *setup.Controller) (*Config, error) {
// ParseHugo parses the configuration file
func ParseHugo(c *setup.Controller) (*Config, error) {
conf := &Config{
Public: strings.Replace(c.Root, "./", "", -1),
Content: "content",
Hugo: true,
Path: "./",
Public: strings.Replace(c.Root, "./", "", -1),
Path: "./",
}
for c.Next() {
@ -46,20 +42,18 @@ func ParseCMS(c *setup.Controller) (*Config, error) {
conf.Styles = strings.TrimPrefix(conf.Styles, "/")
// Add a beginning slash to make a
conf.Styles = "/" + conf.Styles
case "content":
case "args":
if !c.NextArg() {
return nil, c.ArgErr()
}
conf.Content = c.Val()
case "command":
if !c.NextArg() {
return nil, c.ArgErr()
}
conf.Command = c.Val()
if conf.Command != "" && !strings.HasPrefix(conf.Command, "-") {
conf.Hugo = false
// Get the arguments and split the array
args := strings.Split(c.Val(), " ")
for index, element := range args {
args[index] = strings.Replace(element, "\"", "", -1)
}
conf.Args = args
}
}
}

View File

@ -2,7 +2,7 @@
//go:generate go install github.com/jteeuwen/go-bindata/go-bindata
//go:generate go-bindata -pkg assets -o assets/assets.go templates/ assets/css/ assets/js/ assets/fonts/
package cms
package hugo
import (
"mime"
@ -22,21 +22,21 @@ import (
// Setup configures the middleware
func Setup(c *setup.Controller) (middleware.Middleware, error) {
config, _ := config.ParseCMS(c)
config, _ := config.ParseHugo(c)
utils.Run(config)
return func(next middleware.Handler) middleware.Handler {
return &CaddyCMS{Next: next, Config: config}
return &CaddyHugo{Next: next, Config: config}
}, nil
}
// CaddyCMS main type
type CaddyCMS struct {
// CaddyHugo main type
type CaddyHugo struct {
Next middleware.Handler
Config *config.Config
}
func (h CaddyCMS) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
func (h CaddyHugo) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
// Only handle /admin path
if middleware.Path(r.URL.Path).Matches("/admin") {
var err error
@ -60,9 +60,9 @@ func (h CaddyCMS) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error)
}
}
// If the current page is only "/admin/", redirect to "/admin/browse/contents"
// If the current page is only "/admin/", redirect to "/admin/browse/content/"
if r.URL.Path == "/admin/" {
http.Redirect(w, r, "/admin/browse/"+h.Config.Content+"/", http.StatusTemporaryRedirect)
http.Redirect(w, r, "/admin/browse/content/", http.StatusTemporaryRedirect)
return 0, nil
}

View File

@ -2,12 +2,10 @@ package utils
import (
"errors"
"fmt"
"io"
"log"
"net/http"
"os"
"os/exec"
"reflect"
"strings"
"text/template"
@ -174,23 +172,7 @@ func Run(c *config.Config) {
log.Print("Can't get working directory.")
}
if !c.Hugo {
out, err := exec.Command(c.Command).Output()
fmt.Print(string(out))
if err != nil {
log.Panic("Can't execute the commands defined on Caddyfile.")
}
return
}
args := strings.Split(c.Command, " ")
for index, element := range args {
args[index] = strings.Replace(element, "\"", "", -1)
}
commands.HugoCmd.ParseFlags(args)
commands.HugoCmd.ParseFlags(c.Args)
commands.HugoCmd.Run(commands.HugoCmd, make([]string, 0))
err = os.Chdir(cwd)