package caddyhugo import ( "encoding/base64" "fmt" "net/http" "os" "path" "path/filepath" "git.stephensearles.com/stephen/acedoc" "github.com/mholt/caddy/caddyhttp/httpserver" ) func (t tmplData) Content() ([]string, error) { var files []string err := filepath.Walk(path.Join(t.Site.Root, "content"), func(name string, fi os.FileInfo, err error) error { if fi.IsDir() { return nil } files = append(files, name) return nil }) if err != nil { fmt.Println(err) return nil, err } return files, nil } func (t tmplData) ContentTypes() ([]string, error) { layoutDir, err := os.Open(path.Join(t.Site.Root, "archetypes")) if err != nil { fmt.Println("opening layout dir", err) return nil, err } defer layoutDir.Close() names, err := layoutDir.Readdirnames(0) if err != nil { fmt.Println("reading dir", err) return nil, err } out := []string{"default"} for _, name := range names { out = append(out, name[:len(name)-len(filepath.Ext(name))]) } return out, nil } type tmplData struct { Site *httpserver.SiteConfig R *http.Request CaddyHugo Doc *acedoc.Document docref *docref } func (t tmplData) LoadContent() (string, error) { return t.Doc.Contents(), nil } func baseNoExt(name string) string { base := path.Base(name) return base[:len(base)-len(path.Ext(base))] } func (t tmplData) IframeSource() string { name := baseNoExt(t.docref.name) ctype := baseNoExt(path.Dir(t.docref.name)) return fmt.Sprintf("/hugo/draft/%s/%s/%s/", base64.RawURLEncoding.EncodeToString([]byte(t.docref.name)), ctype, name) } var EditPage = `
{{ .LoadContent }}
` var AdminPage = `not implemented` var AuthorPage = `

Create content:

Edit content:

`