revert: adding json support

This commit is contained in:
tycho garen 2013-07-06 23:52:14 -04:00
parent 6c42d3d490
commit 67f4da30b1

View file

@ -15,6 +15,7 @@ package hugolib
import (
"bytes"
"encoding/json"
"launchpad.net/goyaml"
"fmt"
"github.com/theplant/blackfriday"
@ -175,6 +176,38 @@ func (page *Page) parseYamlMetaData(data []byte) ([]string, error) {
return lines, err
}
func (page *Page) parseJsonMetaData(data []byte) ([]string, error) {
var err error
lines := strings.Split(string(data), "\n")
datum := lines[0:]
// go through content parse between "{" and "}"
// must be on their own lines (for now)
var found = 0
for i, line := range lines {
line = strings.TrimSpace(line)
if line == "{" {
found += 1
}
if line == "}" {
found -= 1
}
if found == 0 {
datum = lines[0 : i+1]
lines = lines[i+1:]
break
}
}
err = page.handleJsonMetaData([]byte(strings.Join(datum, "\n")))
return lines, err
}
func (p *Page) Permalink() template.HTML {
if len(strings.TrimSpace(p.Slug)) > 0 {
return template.HTML(MakePermalink(string(p.Site.BaseUrl), strings.TrimSpace(p.Section)+"/"+p.Slug))
@ -267,6 +300,9 @@ func (page *Page) parseFileHeading(data []byte) ([]string, error) {
if len(data) == 0 {
page.Err("Empty File, skipping")
} else {
if data[0] == '{' {
return page.parseJsonMetaData(data)
}
return page.parseYamlMetaData(data)
}
return nil, nil