Former-commit-id: e4a5da856ccf794aa1517ca44e8ee47d83ef0f2d
This commit is contained in:
Henrique Dias
2017-01-18 18:20:56 +00:00
parent b29d284591
commit 3b9c687af7
7 changed files with 69 additions and 31 deletions

View File

@@ -18,7 +18,10 @@ type Editor struct {
Mode string
Visual bool
Content string
FrontMatter *frontmatter.Content
FrontMatter struct {
Content *frontmatter.Content
Rune rune
}
}
// GetEditor gets the editor based on a FileInfo struct
@@ -41,9 +44,10 @@ func GetEditor(r *http.Request, i *file.Info) (*Editor, error) {
if editor.Class == "frontmatter-only" {
// Checks if the file already has the frontmatter rune and parses it
if frontmatter.HasRune(i.Content) {
editor.FrontMatter, _, err = frontmatter.Pretty(i.Content)
editor.FrontMatter.Content, _, err = frontmatter.Pretty(i.Content)
} else {
editor.FrontMatter, _, err = frontmatter.Pretty(frontmatter.AppendRune(i.Content, editor.Mode))
editor.FrontMatter.Rune = frontmatter.StringFormatToRune(editor.Mode)
editor.FrontMatter.Content, _, err = frontmatter.Pretty(frontmatter.AppendRune(i.Content, editor.FrontMatter.Rune))
}
}
@@ -52,12 +56,12 @@ func GetEditor(r *http.Request, i *file.Info) (*Editor, error) {
// Starts a new buffer and parses the file using Hugo's functions
buffer := bytes.NewBuffer(i.Content)
page, err = parser.ReadFrom(buffer)
editor.Class = "complete"
if err == nil {
// Parses the page content and the frontmatter
editor.Content = strings.TrimSpace(string(page.Content()))
editor.FrontMatter, _, err = frontmatter.Pretty(page.FrontMatter())
editor.FrontMatter.Rune = rune(i.Content[0])
editor.FrontMatter.Content, _, err = frontmatter.Pretty(page.FrontMatter())
}
}