diff options
author | Vas Sudanagunta <[email protected]> | 2018-01-25 22:54:15 -0500 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2018-01-26 09:17:27 +0100 |
commit | 91bb774ae4e129f7ed0624754b31479c960ef774 (patch) | |
tree | 9c6d7628e9f5ec7c25842bb8609278da60ab2ec4 /parser/frontmatter.go | |
parent | 3f0379adb72389954ca2be6a9f2ebfcd65c6c440 (diff) | |
download | hugo-91bb774ae4e129f7ed0624754b31479c960ef774.tar.gz hugo-91bb774ae4e129f7ed0624754b31479c960ef774.zip |
Support pages without front matter
* Page without front matter now treated same as a page with empty front matter.
* Test cases added to cover this and repro issue #4320.
* Type safety of front matter code improved.
Fixes #4320
Diffstat (limited to 'parser/frontmatter.go')
-rw-r--r-- | parser/frontmatter.go | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/parser/frontmatter.go b/parser/frontmatter.go index ab56b14d1..7560a734a 100644 --- a/parser/frontmatter.go +++ b/parser/frontmatter.go @@ -31,7 +31,7 @@ import ( // FrontmatterType represents a type of frontmatter. type FrontmatterType struct { // Parse decodes content into a Go interface. - Parse func([]byte) (interface{}, error) + Parse func([]byte) (map[string]interface{}, error) markstart, markend []byte // starting and ending delimiters includeMark bool // include start and end mark in output @@ -168,7 +168,7 @@ func DetectFrontMatter(mark rune) (f *FrontmatterType) { // HandleTOMLMetaData unmarshals TOML-encoded datum and returns a Go interface // representing the encoded data structure. -func HandleTOMLMetaData(datum []byte) (interface{}, error) { +func HandleTOMLMetaData(datum []byte) (map[string]interface{}, error) { m := map[string]interface{}{} datum = removeTOMLIdentifier(datum) @@ -198,7 +198,7 @@ func removeTOMLIdentifier(datum []byte) []byte { // HandleYAMLMetaData unmarshals YAML-encoded datum and returns a Go interface // representing the encoded data structure. -func HandleYAMLMetaData(datum []byte) (interface{}, error) { +func HandleYAMLMetaData(datum []byte) (map[string]interface{}, error) { m := map[string]interface{}{} err := yaml.Unmarshal(datum, &m) return m, err @@ -206,7 +206,7 @@ func HandleYAMLMetaData(datum []byte) (interface{}, error) { // HandleJSONMetaData unmarshals JSON-encoded datum and returns a Go interface // representing the encoded data structure. -func HandleJSONMetaData(datum []byte) (interface{}, error) { +func HandleJSONMetaData(datum []byte) (map[string]interface{}, error) { if datum == nil { // Package json returns on error on nil input. // Return an empty map to be consistent with our other supported @@ -214,13 +214,13 @@ func HandleJSONMetaData(datum []byte) (interface{}, error) { return make(map[string]interface{}), nil } - var f interface{} + var f map[string]interface{} err := json.Unmarshal(datum, &f) return f, err } // HandleOrgMetaData unmarshals org-mode encoded datum and returns a Go // interface representing the encoded data structure. -func HandleOrgMetaData(datum []byte) (interface{}, error) { +func HandleOrgMetaData(datum []byte) (map[string]interface{}, error) { return goorgeous.OrgHeaders(datum) } |