moving front matter parsing (and creation) to parse package

This commit is contained in:
spf13
2014-05-01 13:19:51 -04:00
parent 58f8b43fee
commit cbd9506c29
3 changed files with 197 additions and 88 deletions

View File

@@ -13,9 +13,11 @@ const (
YAML_LEAD = "-"
YAML_DELIM_UNIX = "---\n"
YAML_DELIM_DOS = "---\r\n"
YAML_DELIM = "---"
TOML_LEAD = "+"
TOML_DELIM_UNIX = "+++\n"
TOML_DELIM_DOS = "+++\r\n"
TOML_DELIM = "+++"
JSON_LEAD = "{"
)
@@ -39,6 +41,7 @@ type Page interface {
FrontMatter() FrontMatter
Content() Content
IsRenderable() bool
Metadata() (interface{}, error)
}
type page struct {
@@ -59,6 +62,19 @@ func (p *page) IsRenderable() bool {
return p.render
}
func (p *page) Metadata() (meta interface{}, err error) {
frontmatter := p.FrontMatter()
if len(frontmatter) != 0 {
fm := DetectFrontMatter(rune(frontmatter[0]))
meta, err = fm.Parse(frontmatter)
if err != nil {
return
}
}
return
}
// ReadFrom reads the content from an io.Reader and constructs a page.
func ReadFrom(r io.Reader) (p Page, err error) {
reader := bufio.NewReader(r)