package caddyhugo import ( "encoding/base64" "fmt" "net/http" "os" "path" "path/filepath" "strings" "git.stephensearles.com/stephen/acedoc" "github.com/mholt/caddy/caddyhttp/httpserver" ) func (t *tmplData) Content() ([]Content, error) { return GetContent(t.Site.Root, t.HugoSites) } func (t *tmplData) ContentTypes() ([]string, error) { nameMap := map[string]struct{}{"default": struct{}{}} names, err := t.contentTypes(path.Join(t.Site.Root, "archetypes")) if err != nil { return nil, err } for _, name := range names { nameMap[name] = struct{}{} } names, err = t.contentTypes(path.Join(t.Site.Root, "themes", "hugo-theme-minos", "archetypes")) if err != nil { return nil, err } for _, name := range names { nameMap[name] = struct{}{} } var out []string for name := range nameMap { out = append(out, name[:len(name)-len(filepath.Ext(name))]) } return out, nil } func (t *tmplData) contentTypes(dir string) ([]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 } return names, 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)) if ctype == "content" { return fmt.Sprintf("/hugo/draft/%s/%s/", base64.RawURLEncoding.EncodeToString([]byte(t.docref.name)), strings.Replace(name, " ", "-", -1)) } return fmt.Sprintf("/hugo/draft/%s/%s/%s/", base64.RawURLEncoding.EncodeToString([]byte(t.docref.name)), ctype, strings.Replace(name, " ", "-", -1)) } var EditPage = `
` var AdminPage = `not implemented` var AuthorPage = ` {{ $timeFormat := "Jan _2 15:04:05" }}

Create content:

Edit content:

{{ range .Content }} {{ if .Metadata }} {{ else }} {{ end }} {{- end }}
{{ .Metadata.Title }} {{ .Metadata.Date.Format $timeFormat }} {{ if not (.Metadata.Lastmod.Equal .Metadata.Date) }} (last modified {{.Metadata.Lastmod.Format $timeFormat }}) {{end}} {{ .Filename }} (unable to load metadata)
` func UploadPage(elemName string) string { return fmt.Sprintf(` `, elemName, elemName, elemName, elemName, elemName, elemName) }