Switch to a more up to date TOML library

Fixes #2089
This commit is contained in:
Bjørn Erik Pedersen 2016-08-20 20:28:38 +01:00
parent 81f04ef4f0
commit 20c4311df4
3 changed files with 19 additions and 16 deletions

View file

@ -317,7 +317,7 @@ func newContentPathSection(path string) (string, string) {
} }
func createConfig(inpath string, kind string) (err error) { 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/", "baseurl": "http://replace-this-with-your-hugo-site.com/",
"title": "My New Hugo Site", "title": "My New Hugo Site",
"languageCode": "en-us", "languageCode": "en-us",

View file

@ -20,7 +20,7 @@ import (
"path/filepath" "path/filepath"
"github.com/BurntSushi/toml" toml "github.com/pelletier/go-toml"
"github.com/spf13/hugo/hugofs" "github.com/spf13/hugo/hugofs"
"github.com/spf13/hugo/source" "github.com/spf13/hugo/source"
"github.com/spf13/viper" "github.com/spf13/viper"
@ -701,11 +701,12 @@ func testSiteSetup(s *Site, t *testing.T) {
} }
func tomlToMap(s string) (map[string]interface{}, error) { func tomlToMap(s string) (map[string]interface{}, error) {
var data = make(map[string]interface{}) tree, err := toml.Load(s)
if _, err := toml.Decode(s, &data); err != nil {
if err != nil {
return nil, err return nil, err
} }
return data, nil return tree.ToMap(), nil
} }

View file

@ -19,7 +19,8 @@ import (
"fmt" "fmt"
"strings" "strings"
"github.com/BurntSushi/toml" toml "github.com/pelletier/go-toml"
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
) )
@ -49,11 +50,8 @@ func InterfaceToConfig(in interface{}, mark rune) ([]byte, error) {
} }
return b.Bytes(), nil return b.Bytes(), nil
case rune(TOMLLead[0]): case rune(TOMLLead[0]):
err := toml.NewEncoder(b).Encode(in) tree := toml.TreeFromMap(in.(map[string]interface{}))
if err != nil { return []byte(tree.String()), nil
return nil, err
}
return b.Bytes(), nil
case rune(JSONLead[0]): case rune(JSONLead[0]):
by, err := json.MarshalIndent(in, "", " ") by, err := json.MarshalIndent(in, "", " ")
if err != nil { if err != nil {
@ -99,10 +97,8 @@ func InterfaceToFrontMatter(in interface{}, mark rune) ([]byte, error) {
return nil, err return nil, err
} }
err = toml.NewEncoder(b).Encode(in) tree := toml.TreeFromMap(in.(map[string]interface{}))
if err != nil { b.Write([]byte(tree.String()))
return nil, err
}
_, err = b.Write([]byte("\n" + TOMLDelimUnix)) _, err = b.Write([]byte("\n" + TOMLDelimUnix))
if err != nil { if err != nil {
return nil, err return nil, err
@ -166,9 +162,15 @@ func DetectFrontMatter(mark rune) (f *frontmatterType) {
func HandleTOMLMetaData(datum []byte) (interface{}, error) { func HandleTOMLMetaData(datum []byte) (interface{}, error) {
m := map[string]interface{}{} m := map[string]interface{}{}
datum = removeTOMLIdentifier(datum) datum = removeTOMLIdentifier(datum)
if _, err := toml.Decode(string(datum), &m); err != nil {
tree, err := toml.Load(string(datum))
if err != nil {
return m, err return m, err
} }
m = tree.ToMap()
return m, nil return m, nil
} }