diff options
author | Bjørn Erik Pedersen <[email protected]> | 2016-08-20 20:28:38 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2016-08-20 20:33:06 +0100 |
commit | 20c4311df4e61edb449ec93837cdde96a700b879 (patch) | |
tree | 992334fac5cd41dbe946fc83c205c64964dda591 /parser/frontmatter.go | |
parent | 81f04ef4f0acf518e78846d4d15c07c531a08546 (diff) | |
download | hugo-20c4311df4e61edb449ec93837cdde96a700b879.tar.gz hugo-20c4311df4e61edb449ec93837cdde96a700b879.zip |
Switch to a more up to date TOML library
Fixes #2089
Diffstat (limited to 'parser/frontmatter.go')
-rw-r--r-- | parser/frontmatter.go | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/parser/frontmatter.go b/parser/frontmatter.go index 40418e684..b4ed54bcd 100644 --- a/parser/frontmatter.go +++ b/parser/frontmatter.go @@ -19,7 +19,8 @@ import ( "fmt" "strings" - "github.com/BurntSushi/toml" + toml "github.com/pelletier/go-toml" + "gopkg.in/yaml.v2" ) @@ -49,11 +50,8 @@ func InterfaceToConfig(in interface{}, mark rune) ([]byte, error) { } return b.Bytes(), nil case rune(TOMLLead[0]): - err := toml.NewEncoder(b).Encode(in) - if err != nil { - return nil, err - } - return b.Bytes(), nil + tree := toml.TreeFromMap(in.(map[string]interface{})) + return []byte(tree.String()), nil case rune(JSONLead[0]): by, err := json.MarshalIndent(in, "", " ") if err != nil { @@ -99,10 +97,8 @@ func InterfaceToFrontMatter(in interface{}, mark rune) ([]byte, error) { return nil, err } - err = toml.NewEncoder(b).Encode(in) - if err != nil { - return nil, err - } + tree := toml.TreeFromMap(in.(map[string]interface{})) + b.Write([]byte(tree.String())) _, err = b.Write([]byte("\n" + TOMLDelimUnix)) if err != nil { return nil, err @@ -166,9 +162,15 @@ func DetectFrontMatter(mark rune) (f *frontmatterType) { func HandleTOMLMetaData(datum []byte) (interface{}, error) { m := map[string]interface{}{} datum = removeTOMLIdentifier(datum) - if _, err := toml.Decode(string(datum), &m); err != nil { + + tree, err := toml.Load(string(datum)) + + if err != nil { return m, err } + + m = tree.ToMap() + return m, nil } |