shithub: hugo

Download patch

ref: 20c4311df4e61edb449ec93837cdde96a700b879
parent: 81f04ef4f0acf518e78846d4d15c07c531a08546
author: Bjørn Erik Pedersen <[email protected]>
date: Sat Aug 20 16:28:38 EDT 2016

Switch to a more up to date TOML library

Fixes #2089

--- a/commands/new.go
+++ b/commands/new.go
@@ -317,7 +317,7 @@
 }
 
 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",
--- a/hugolib/menu_test.go
+++ b/hugolib/menu_test.go
@@ -20,7 +20,7 @@
 
 	"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 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
 
 }
--- a/parser/frontmatter.go
+++ b/parser/frontmatter.go
@@ -19,7 +19,8 @@
 	"fmt"
 	"strings"
 
-	"github.com/BurntSushi/toml"
+	toml "github.com/pelletier/go-toml"
+
 	"gopkg.in/yaml.v2"
 )
 
@@ -49,11 +50,8 @@
 		}
 		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 @@
 			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 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
 }