Skip to content

Commit

Permalink
Switch to a more up to date TOML library
Browse files Browse the repository at this point in the history
  • Loading branch information
bep authored and tychoish committed Aug 13, 2017
1 parent 2b33fab commit 9713037
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion commands/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 5 additions & 4 deletions hugolib/menu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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

}
24 changes: 13 additions & 11 deletions parser/frontmatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import (
"fmt"
"strings"

"github.com/BurntSushi/toml"
toml "github.com/pelletier/go-toml"

"gopkg.in/yaml.v2"
)

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 9713037

Please sign in to comment.