diff options
author | spf13 <steve.francia@gmail.com> | 2014-05-01 21:19:51 +0400 |
---|---|---|
committer | spf13 <steve.francia@gmail.com> | 2014-05-01 21:20:09 +0400 |
commit | cbd9506c296dba99c59fef310a16b21be12b7b63 (patch) | |
tree | 8fdb6ccd3189e6889bc09cf786497d94d29a4820 /parser/page.go | |
parent | 58f8b43feed9a487e63b61352226d934743ebafe (diff) |
moving front matter parsing (and creation) to parse package
Diffstat (limited to 'parser/page.go')
-rw-r--r-- | parser/page.go | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/parser/page.go b/parser/page.go index c0e1eebc4..a3c0ec7d7 100644 --- a/parser/page.go +++ b/parser/page.go @@ -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) |