frontmatter parsing better; edit not working
This commit is contained in:
26
edit/edit.go
26
edit/edit.go
@@ -7,13 +7,16 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/hacdias/caddy-hugo/frontmatter"
|
||||
"github.com/hacdias/caddy-hugo/page"
|
||||
"github.com/spf13/hugo/commands"
|
||||
"github.com/spf13/hugo/parser"
|
||||
)
|
||||
|
||||
type fileInfo struct {
|
||||
Content string
|
||||
Name string
|
||||
type information struct {
|
||||
Name string
|
||||
Content string
|
||||
FrontMatter interface{}
|
||||
}
|
||||
|
||||
// Execute sth
|
||||
@@ -36,21 +39,28 @@ func Execute(w http.ResponseWriter, r *http.Request) (int, error) {
|
||||
return 404, nil
|
||||
}
|
||||
|
||||
file, err := ioutil.ReadFile(filename)
|
||||
reader, err := os.Open(filename)
|
||||
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
return 500, err
|
||||
}
|
||||
|
||||
inf := new(fileInfo)
|
||||
inf.Content = string(file)
|
||||
inf.Name = filename
|
||||
file, err := parser.ReadFrom(reader)
|
||||
|
||||
inf := new(information)
|
||||
inf.Content = string(file.Content())
|
||||
inf.FrontMatter, err = frontmatter.Pretty(file.FrontMatter())
|
||||
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
return 500, err
|
||||
}
|
||||
|
||||
page := new(page.Page)
|
||||
page.Title = "Edit"
|
||||
page.Body = inf
|
||||
return page.Render(w, r, "edit")
|
||||
return page.Render(w, r, "edit", "frontmatter")
|
||||
}
|
||||
|
||||
return 200, nil
|
||||
|
||||
Reference in New Issue
Block a user