You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
103 lines
2.1 KiB
103 lines
2.1 KiB
package caddyhugo
|
|
|
|
import (
|
|
"fmt"
|
|
"html/template"
|
|
"log"
|
|
"os"
|
|
"path"
|
|
|
|
"git.stephensearles.com/stephen/caddy-hugo2/comments"
|
|
"git.stephensearles.com/stephen/caddy-hugo2/media"
|
|
|
|
"github.com/gohugoio/hugo/hugofs"
|
|
)
|
|
|
|
var eventHookCounter uint64
|
|
|
|
/*
|
|
func SetupCaddy(c *caddy.Controller) error {
|
|
ch := &CaddyHugo{}
|
|
|
|
ch.Site = httpserver.GetConfig(c)
|
|
root, err := filepath.Abs(ch.Site.Root)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
err = ch.Setup(root)
|
|
|
|
c.OnShutdown(func() error {
|
|
return ch.persistAllEdits()
|
|
})
|
|
|
|
ch.Site.AddMiddleware(ch.Middleware(c))
|
|
ch.commentsSetting(c)
|
|
|
|
return err
|
|
}
|
|
*/
|
|
|
|
func (ch *CaddyHugo) commentsSetting() {
|
|
if ch.Site.CommentsEnabled {
|
|
ch.Comments = comments.WithStorage(comments.NewDiskv(path.Join(ch.Site.Root, "comments")))
|
|
if ch.Site.CommentsPassword != "" {
|
|
ch.Comments.Password = ch.Site.CommentsPassword
|
|
}
|
|
}
|
|
}
|
|
|
|
func (ch *CaddyHugo) Setup(dir string) error {
|
|
var err error
|
|
|
|
log.Println("setting up caddy-hugo in", dir)
|
|
ch.Dir = dir
|
|
ch.docs = make(map[string]*editSession)
|
|
ch.confirmingToClient = make(map[uint64]struct{})
|
|
|
|
ch.HugoSites, ch.HugoCfg, err = ch.configWithFs(hugofs.Os)
|
|
if err != nil {
|
|
return fmt.Errorf("error setting up hugo : %v", err)
|
|
}
|
|
|
|
err = ch.Build()
|
|
if err != nil {
|
|
return fmt.Errorf("error building initial hugo: %v", err)
|
|
}
|
|
|
|
ch.authorTmpl, err = template.New("").Parse(AuthorPage)
|
|
if err != nil {
|
|
return fmt.Errorf("author template invalid: %v", err)
|
|
}
|
|
|
|
ch.adminTmpl, err = template.New("").Parse(AdminPage)
|
|
if err != nil {
|
|
return fmt.Errorf("admin template invalid: %v", err)
|
|
}
|
|
|
|
ch.editTmpl, err = template.New("").Parse(EditPage)
|
|
if err != nil {
|
|
return fmt.Errorf("edit template invalid: %v", err)
|
|
}
|
|
|
|
ch.Media = &media.MediaSource{
|
|
StorageDir: path.Join(dir, "media"),
|
|
ThumbDir: path.Join(dir, "thumbs"),
|
|
}
|
|
|
|
err = os.MkdirAll(ch.Media.StorageDir, 0755)
|
|
if err != nil {
|
|
return fmt.Errorf("couldn't initialize media: %v", err)
|
|
}
|
|
|
|
err = writeThemeFiles(ch.Dir)
|
|
if err != nil {
|
|
fmt.Println("error installing theme files:", err)
|
|
}
|
|
|
|
err = ch.Publish()
|
|
if err != nil {
|
|
fmt.Println("error with initial publish of hugo site:", err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|