Switch to a more up to date TOML library
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sat, 20 Aug 2016 19:28:38 +0000 (20:28 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sat, 20 Aug 2016 19:33:06 +0000 (20:33 +0100)
Fixes #2089

commands/new.go
hugolib/menu_test.go
parser/frontmatter.go

index fe4ed75e17c78dfeb291a7c84dc543a58057155b..4cd8d7197ac672366a260d58ca3debb680cb313a 100644 (file)
@@ -317,7 +317,7 @@ func newContentPathSection(path string) (string, string) {
 }
 
 func createConfig(inpath string, kind string) (err error) {
-       in := map[string]string{
+       in := map[string]interface{}{
                "baseurl":      "http://replace-this-with-your-hugo-site.com/",
                "title":        "My New Hugo Site",
                "languageCode": "en-us",
index c7a6a4f05613e1f3eaefb44a534245f0358ba79e..df6ccf629ceaf3d3ffbe1de98e0c5cf2c38071c8 100644 (file)
@@ -20,7 +20,7 @@ import (
 
        "path/filepath"
 
-       "github.com/BurntSushi/toml"
+       toml "github.com/pelletier/go-toml"
        "github.com/spf13/hugo/hugofs"
        "github.com/spf13/hugo/source"
        "github.com/spf13/viper"
@@ -701,11 +701,12 @@ func testSiteSetup(s *Site, t *testing.T) {
 }
 
 func tomlToMap(s string) (map[string]interface{}, error) {
-       var data = make(map[string]interface{})
-       if _, err := toml.Decode(s, &data); err != nil {
+       tree, err := toml.Load(s)
+
+       if err != nil {
                return nil, err
        }
 
-       return data, nil
+       return tree.ToMap(), nil
 
 }
index 40418e684f526d2a25a62c7a02c2e5ecf43ec35c..b4ed54bcd9b1f4652f8e5fe8d5414291ff2961bc 100644 (file)
@@ -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
 }