commit
ba966e725c
18
README.md
18
README.md
|
@ -1,13 +1,13 @@
|
||||||
# caddy-cms
|
# caddy-hugo
|
||||||
|
|
||||||
[](https://travis-ci.org/hacdias/caddy-cms)
|
[](https://travis-ci.org/hacdias/caddy-hugo)
|
||||||
[](http://godoc.org/github.com/hacdias/caddy-cms)
|
[](http://godoc.org/github.com/hacdias/caddy-hugo)
|
||||||
|
|
||||||
Powerful and easy static site generator with admin interface. By default it uses [Hugo](http://gohugo.io/) (and you don't need to install it separately) but you can use whatever you want.
|
Powerful and easy static site generator with admin interface with [Hugo](http://gohugo.io/) (and you don't need to install it separately).
|
||||||
|
|
||||||
## Build it from source
|
## Build it from source
|
||||||
|
|
||||||
If you want to try caddy-cms plugin (and improve it maybe), you'll have to install some tools.
|
If you want to try caddy-hugo plugin (and improve it maybe), you'll have to install some tools.
|
||||||
|
|
||||||
+ [Go 1.4 or higher](https://golang.org/dl/)
|
+ [Go 1.4 or higher](https://golang.org/dl/)
|
||||||
+ [caddydev](https://github.com/caddyserver/caddydev)
|
+ [caddydev](https://github.com/caddyserver/caddydev)
|
||||||
|
@ -22,7 +22,7 @@ If you want to go deeper and make changes in front-end assets like JavaScript or
|
||||||
|
|
||||||
### Run it
|
### Run it
|
||||||
|
|
||||||
If you have already installed everything above to meet the requirements for what you want to do, let's start. Firstly, open the terminal and navigate to your clone of ```caddy-cms```. Then execute:
|
If you have already installed everything above to meet the requirements for what you want to do, let's start. Firstly, open the terminal and navigate to your clone of ```caddy-hugo```. Then execute:
|
||||||
|
|
||||||
```
|
```
|
||||||
go-bindata [-debug] -pkg assets -o assets/assets.go templates/ assets/css/ assets/js/ assets/fonts/
|
go-bindata [-debug] -pkg assets -o assets/assets.go templates/ assets/css/ assets/js/ assets/fonts/
|
||||||
|
@ -32,14 +32,14 @@ That command will create an ```assets.go``` file which contains all static files
|
||||||
|
|
||||||
Now, open the folder with your static website and create a Caddyfile. Read the [docs](http://caddyserver.com/docs/cms) for more information about the directives of this plugin.
|
Now, open the folder with your static website and create a Caddyfile. Read the [docs](http://caddyserver.com/docs/cms) for more information about the directives of this plugin.
|
||||||
|
|
||||||
After creating the file, navigate to that folder using the terminal and run the following command, replacing ```{caddy-cms}``` with the location of your clone.
|
After creating the file, navigate to that folder using the terminal and run the following command, replacing ```{caddy-hugo}``` with the location of your clone.
|
||||||
|
|
||||||
```
|
```
|
||||||
caddydev --source {caddy-cms} hugo
|
caddydev --source {caddy-hugo} hugo
|
||||||
```
|
```
|
||||||
|
|
||||||
Navigate to the url you set on Caddyfile to see your blog running on Caddy and Hugo. Go to ```/admin``` to try the Admin UI.
|
Navigate to the url you set on Caddyfile to see your blog running on Caddy and Hugo. Go to ```/admin``` to try the Admin UI.
|
||||||
|
|
||||||
Everything is working now. Whenever you make a change in the back-end source code, you'll have to run the command above again.
|
Everything is working now. Whenever you make a change in the back-end source code, you'll have to run the command above again.
|
||||||
|
|
||||||
**For those who want to make changes in front-end**, make sure you have every needed tool installed and run ```npm install``` in the root of ```caddy-cms``` clone. Then, run ```grunt watch```.
|
**For those who want to make changes in front-end**, make sure you have every needed tool installed and run ```npm install``` in the root of ```caddy-hugo``` clone. Then, run ```grunt watch```.
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
package browse
|
package browse
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/hacdias/caddy-cms/config"
|
"github.com/hacdias/caddy-hugo/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ServeHTTP is used to serve the content of Browse page
|
// ServeHTTP is used to serve the content of Browse page
|
||||||
|
@ -21,6 +22,6 @@ func ServeHTTP(w http.ResponseWriter, r *http.Request, c *config.Config) (int, e
|
||||||
case "GET":
|
case "GET":
|
||||||
return GET(w, r, c)
|
return GET(w, r, c)
|
||||||
default:
|
default:
|
||||||
return 400, nil
|
return 400, errors.New("Invalid method.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/hacdias/caddy-cms/config"
|
"github.com/hacdias/caddy-hugo/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DELETE handles the DELETE method on browse page
|
// DELETE handles the DELETE method on browse page
|
||||||
|
|
|
@ -4,8 +4,8 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
"github.com/hacdias/caddy-cms/config"
|
"github.com/hacdias/caddy-hugo/config"
|
||||||
"github.com/hacdias/caddy-cms/utils"
|
"github.com/hacdias/caddy-hugo/utils"
|
||||||
"github.com/mholt/caddy/middleware"
|
"github.com/mholt/caddy/middleware"
|
||||||
"github.com/mholt/caddy/middleware/browse"
|
"github.com/mholt/caddy/middleware/browse"
|
||||||
)
|
)
|
||||||
|
|
|
@ -10,8 +10,8 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/hacdias/caddy-cms/config"
|
"github.com/hacdias/caddy-hugo/config"
|
||||||
"github.com/hacdias/caddy-cms/utils"
|
"github.com/hacdias/caddy-hugo/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
// POST handles the POST method on browse page
|
// POST handles the POST method on browse page
|
||||||
|
@ -132,6 +132,8 @@ func upload(w http.ResponseWriter, r *http.Request) (int, error) {
|
||||||
w.Write([]byte(err.Error()))
|
w.Write([]byte(err.Error()))
|
||||||
return http.StatusInternalServerError, err
|
return http.StatusInternalServerError, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defer outfile.Close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,21 +8,17 @@ import (
|
||||||
|
|
||||||
// Config is the add-on configuration set on Caddyfile
|
// Config is the add-on configuration set on Caddyfile
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Public string
|
Public string // Public content path
|
||||||
Content string
|
Path string // Hugo files path
|
||||||
Path string
|
Styles string // Admin styles path
|
||||||
Styles string
|
Args []string // Hugo arguments
|
||||||
Command string
|
|
||||||
Hugo bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseCMS parses the configuration file
|
// ParseHugo parses the configuration file
|
||||||
func ParseCMS(c *setup.Controller) (*Config, error) {
|
func ParseHugo(c *setup.Controller) (*Config, error) {
|
||||||
conf := &Config{
|
conf := &Config{
|
||||||
Public: strings.Replace(c.Root, "./", "", -1),
|
Public: strings.Replace(c.Root, "./", "", -1),
|
||||||
Content: "content",
|
Path: "./",
|
||||||
Hugo: true,
|
|
||||||
Path: "./",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for c.Next() {
|
for c.Next() {
|
||||||
|
@ -46,20 +42,18 @@ func ParseCMS(c *setup.Controller) (*Config, error) {
|
||||||
conf.Styles = strings.TrimPrefix(conf.Styles, "/")
|
conf.Styles = strings.TrimPrefix(conf.Styles, "/")
|
||||||
// Add a beginning slash to make a
|
// Add a beginning slash to make a
|
||||||
conf.Styles = "/" + conf.Styles
|
conf.Styles = "/" + conf.Styles
|
||||||
case "content":
|
case "args":
|
||||||
if !c.NextArg() {
|
if !c.NextArg() {
|
||||||
return nil, c.ArgErr()
|
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, "-") {
|
// Get the arguments and split the array
|
||||||
conf.Hugo = false
|
args := strings.Split(c.Val(), " ")
|
||||||
|
for index, element := range args {
|
||||||
|
args[index] = strings.Replace(element, "\"", "", -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
conf.Args = args
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
package editor
|
package editor
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/hacdias/caddy-cms/config"
|
"github.com/hacdias/caddy-hugo/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ServeHTTP serves the editor page
|
// ServeHTTP serves the editor page
|
||||||
|
@ -18,6 +19,6 @@ func ServeHTTP(w http.ResponseWriter, r *http.Request, c *config.Config) (int, e
|
||||||
case "GET":
|
case "GET":
|
||||||
return GET(w, r, c, filename)
|
return GET(w, r, c, filename)
|
||||||
default:
|
default:
|
||||||
return 400, nil
|
return 400, errors.New("Invalid method.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,9 +10,9 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
"github.com/hacdias/caddy-cms/config"
|
"github.com/hacdias/caddy-hugo/config"
|
||||||
"github.com/hacdias/caddy-cms/frontmatter"
|
"github.com/hacdias/caddy-hugo/frontmatter"
|
||||||
"github.com/hacdias/caddy-cms/utils"
|
"github.com/hacdias/caddy-hugo/utils"
|
||||||
"github.com/spf13/hugo/parser"
|
"github.com/spf13/hugo/parser"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -10,8 +10,8 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/hacdias/caddy-cms/config"
|
"github.com/hacdias/caddy-hugo/config"
|
||||||
"github.com/hacdias/caddy-cms/utils"
|
"github.com/hacdias/caddy-hugo/utils"
|
||||||
"github.com/robfig/cron"
|
"github.com/robfig/cron"
|
||||||
"github.com/spf13/hugo/parser"
|
"github.com/spf13/hugo/parser"
|
||||||
)
|
)
|
||||||
|
@ -81,7 +81,7 @@ func parseFrontMatterOnlyFile(rawFile map[string]interface{}, filename string) (
|
||||||
case "yaml":
|
case "yaml":
|
||||||
mark = rune('-')
|
mark = rune('-')
|
||||||
default:
|
default:
|
||||||
return []byte{}, http.StatusBadRequest, errors.New("can't define the frontmatter")
|
return []byte{}, http.StatusBadRequest, errors.New("Can't define the frontmatter.")
|
||||||
}
|
}
|
||||||
|
|
||||||
f, err := parser.InterfaceToFrontMatter(rawFile, mark)
|
f, err := parser.InterfaceToFrontMatter(rawFile, mark)
|
||||||
|
@ -117,7 +117,7 @@ func parseCompleteFile(r *http.Request, c *config.Config, rawFile map[string]int
|
||||||
|
|
||||||
// Schedule the post
|
// Schedule the post
|
||||||
if r.Header.Get("X-Schedule") == "true" {
|
if r.Header.Get("X-Schedule") == "true" {
|
||||||
t, err := time.Parse("http.StatusOK6-01-02 15:04:05-07:00", rawFile["date"].(string))
|
t, err := time.Parse("2006-01-02 15:04:05-07:00", rawFile["date"].(string))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return []byte{}, http.StatusInternalServerError, err
|
return []byte{}, http.StatusInternalServerError, err
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/hacdias/caddy-cms/utils"
|
"github.com/hacdias/caddy-hugo/utils"
|
||||||
"github.com/spf13/hugo/parser"
|
"github.com/spf13/hugo/parser"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
//go:generate go install github.com/jteeuwen/go-bindata/go-bindata
|
//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/
|
//go:generate go-bindata -pkg assets -o assets/assets.go templates/ assets/css/ assets/js/ assets/fonts/
|
||||||
|
|
||||||
package cms
|
package hugo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"mime"
|
"mime"
|
||||||
|
@ -11,32 +11,32 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/hacdias/caddy-cms/assets"
|
"github.com/hacdias/caddy-hugo/assets"
|
||||||
"github.com/hacdias/caddy-cms/browse"
|
"github.com/hacdias/caddy-hugo/browse"
|
||||||
"github.com/hacdias/caddy-cms/config"
|
"github.com/hacdias/caddy-hugo/config"
|
||||||
"github.com/hacdias/caddy-cms/editor"
|
"github.com/hacdias/caddy-hugo/editor"
|
||||||
"github.com/hacdias/caddy-cms/utils"
|
"github.com/hacdias/caddy-hugo/utils"
|
||||||
"github.com/mholt/caddy/config/setup"
|
"github.com/mholt/caddy/config/setup"
|
||||||
"github.com/mholt/caddy/middleware"
|
"github.com/mholt/caddy/middleware"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Setup configures the middleware
|
// Setup configures the middleware
|
||||||
func Setup(c *setup.Controller) (middleware.Middleware, error) {
|
func Setup(c *setup.Controller) (middleware.Middleware, error) {
|
||||||
config, _ := config.ParseCMS(c)
|
config, _ := config.ParseHugo(c)
|
||||||
utils.Run(config)
|
utils.Run(config)
|
||||||
|
|
||||||
return func(next middleware.Handler) middleware.Handler {
|
return func(next middleware.Handler) middleware.Handler {
|
||||||
return &CaddyCMS{Next: next, Config: config}
|
return &CaddyHugo{Next: next, Config: config}
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// CaddyCMS main type
|
// CaddyHugo main type
|
||||||
type CaddyCMS struct {
|
type CaddyHugo struct {
|
||||||
Next middleware.Handler
|
Next middleware.Handler
|
||||||
Config *config.Config
|
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
|
// Only handle /admin path
|
||||||
if middleware.Path(r.URL.Path).Matches("/admin") {
|
if middleware.Path(r.URL.Path).Matches("/admin") {
|
||||||
var err error
|
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/" {
|
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
|
return 0, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,15 +4,15 @@
|
||||||
"description": "Deploy your Hugo website and enjoy of an admin interface with Caddy server.",
|
"description": "Deploy your Hugo website and enjoy of an admin interface with Caddy server.",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/hacdias/caddy-cms.git"
|
"url": "git+https://github.com/hacdias/caddy-hugo.git"
|
||||||
},
|
},
|
||||||
"main": "Gruntfile.js",
|
"main": "Gruntfile.js",
|
||||||
"author": "Henrique Dias <hacdias@gmail.com>",
|
"author": "Henrique Dias <hacdias@gmail.com>",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/hacdias/caddy-cms/issues"
|
"url": "https://github.com/hacdias/caddy-hugo/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/hacdias/caddy-cms#readme",
|
"homepage": "https://github.com/hacdias/caddy-hugo#readme",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"install": "napa defunkt/jquery-pjax"
|
"install": "napa defunkt/jquery-pjax"
|
||||||
},
|
},
|
||||||
|
|
|
@ -2,19 +2,17 @@ package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
"unicode"
|
"unicode"
|
||||||
|
|
||||||
"github.com/hacdias/caddy-cms/assets"
|
"github.com/hacdias/caddy-hugo/assets"
|
||||||
"github.com/hacdias/caddy-cms/config"
|
"github.com/hacdias/caddy-hugo/config"
|
||||||
"github.com/spf13/hugo/commands"
|
"github.com/spf13/hugo/commands"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -174,23 +172,7 @@ func Run(c *config.Config) {
|
||||||
log.Print("Can't get working directory.")
|
log.Print("Can't get working directory.")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !c.Hugo {
|
commands.HugoCmd.ParseFlags(c.Args)
|
||||||
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.Run(commands.HugoCmd, make([]string, 0))
|
commands.HugoCmd.Run(commands.HugoCmd, make([]string, 0))
|
||||||
|
|
||||||
err = os.Chdir(cwd)
|
err = os.Chdir(cwd)
|
||||||
|
|
Loading…
Reference in New Issue