mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-07 20:30:36 -05:00
fixes: returning json parsing, error messages, yaml header offsets
This commit is contained in:
parent
67f4da30b1
commit
b024454ea9
2 changed files with 23 additions and 11 deletions
|
@ -16,7 +16,7 @@ Somethings are better shown than explained. The following is a very basic exampl
|
|||
Topics": [ "Development", "GoLang" ]
|
||||
Slug": "nitro"
|
||||
project_url": "http://github.com/spf13/nitro"
|
||||
...
|
||||
---
|
||||
|
||||
# Nitro
|
||||
|
||||
|
|
|
@ -165,14 +165,13 @@ func (page *Page) parseYamlMetaData(data []byte) ([]string, error) {
|
|||
}
|
||||
|
||||
if found == 0 {
|
||||
datum = lines[0: i+1]
|
||||
lines = lines[i+1:]
|
||||
datum = lines[1: i+2]
|
||||
lines = lines[i+3:]
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
err = page.handleYamlMetaData([]byte(strings.Join(datum, "\n")))
|
||||
|
||||
err = page.handleMetaData(page.handleYamlMetaData([]byte(strings.Join(datum, "\n"))))
|
||||
return lines, err
|
||||
}
|
||||
|
||||
|
@ -203,8 +202,7 @@ func (page *Page) parseJsonMetaData(data []byte) ([]string, error) {
|
|||
}
|
||||
}
|
||||
|
||||
err = page.handleJsonMetaData([]byte(strings.Join(datum, "\n")))
|
||||
|
||||
err = page.handleMetaData(page.handleJsonMetaData([]byte(strings.Join(datum, "\n"))))
|
||||
return lines, err
|
||||
}
|
||||
|
||||
|
@ -220,11 +218,25 @@ func (p *Page) Permalink() template.HTML {
|
|||
}
|
||||
}
|
||||
|
||||
func (page *Page) handleYamlMetaData(datum []byte) error {
|
||||
func (page *Page) handleYamlMetaData(datum []byte) interface{} {
|
||||
m := map[string]interface{}{}
|
||||
if err := goyaml.Unmarshal(datum, &m); err != nil {
|
||||
return fmt.Errorf("Invalid YAML in $v \nError parsing page meta data: %s", page.FileName, err)
|
||||
return fmt.Errorf("Invalid YAML in %s \nError parsing page meta data: %s", page.FileName, err)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
|
||||
func (page *Page) handleJsonMetaData(datum []byte) interface{} {
|
||||
var f interface{}
|
||||
if err := json.Unmarshal(datum, &f); err != nil {
|
||||
return fmt.Errorf("Invalide JSON in $v \nError parsing page meta data: %s", page.FileName, err)
|
||||
}
|
||||
return f
|
||||
}
|
||||
|
||||
func (page *Page) handleMetaData(f interface{}) error {
|
||||
m := f.(map[string]interface{})
|
||||
|
||||
for k, v := range m {
|
||||
switch strings.ToLower(k) {
|
||||
|
@ -271,8 +283,8 @@ func (page *Page) handleYamlMetaData(datum []byte) error {
|
|||
}
|
||||
}
|
||||
}
|
||||
//Printer(page.Params)
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (page *Page) GetParam(key string) interface{} {
|
||||
|
@ -388,7 +400,7 @@ func (page *Page) convertRestructuredText(lines []string) {
|
|||
var out bytes.Buffer
|
||||
cmd.Stdout = &out
|
||||
if err := cmd.Run(); err != nil {
|
||||
print(err)
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
content := out.String()
|
||||
|
|
Loading…
Reference in a new issue