Skip to content

Commit 0907a5c

Browse files
committed
all: Temporarily revert to BurntSushi for TOML front matter handling
We still have go-toml as a transitive dependency, and it is the way to go eventually, but we care about speed, so let us wait that one out. Note that the issue this fixes is about taxonomies, but I guess this is a general issue for sites with many pages that uses TOML as front matter. ``` benchmark old ns/op new ns/op delta BenchmarkFrontmatterTags/TOML:1-4 23206 8543 -63.19% BenchmarkFrontmatterTags/TOML:11-4 80117 18495 -76.92% BenchmarkFrontmatterTags/TOML:21-4 140676 28727 -79.58% benchmark old allocs new allocs delta BenchmarkFrontmatterTags/TOML:1-4 173 60 -65.32% BenchmarkFrontmatterTags/TOML:11-4 625 138 -77.92% BenchmarkFrontmatterTags/TOML:21-4 1106 210 -81.01% benchmark old bytes new bytes delta BenchmarkFrontmatterTags/TOML:1-4 9231 2912 -68.45% BenchmarkFrontmatterTags/TOML:11-4 19808 5184 -73.83% BenchmarkFrontmatterTags/TOML:21-4 31200 7536 -75.85% ``` See #3541 Updates #3464
1 parent 3d9c4f5 commit 0907a5c

File tree

3 files changed

+9
-24
lines changed

3 files changed

+9
-24
lines changed

‎commands/new.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ func newContentPathSection(path string) (string, string) {
355355
}
356356

357357
func createConfig(fs *hugofs.Fs, inpath string, kind string) (err error) {
358-
in := map[string]interface{}{
358+
in := map[string]string{
359359
"baseURL": "http://example.org/",
360360
"title": "My New Hugo Site",
361361
"languageCode": "en-us",

‎hugolib/menu_old_test.go‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525

2626
"path/filepath"
2727

28-
toml "github.com/pelletier/go-toml"
28+
"github.com/BurntSushi/toml"
2929
"github.com/spf13/hugo/source"
3030
"github.com/stretchr/testify/assert"
3131
"github.com/stretchr/testify/require"
@@ -634,12 +634,7 @@ func setupMenuTests(t *testing.T, pageSources []source.ByteSource, configKeyValu
634634
}
635635

636636
func tomlToMap(s string) (map[string]interface{}, error) {
637-
tree, err := toml.Load(s)
638-
639-
if err != nil {
640-
return nil, err
641-
}
642-
643-
return tree.ToMap(), nil
644-
637+
var data = make(map[string]interface{})
638+
_, err := toml.Decode(s, &data)
639+
return data, err
645640
}

‎parser/frontmatter.go‎

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import (
2020
"io"
2121
"strings"
2222

23+
"github.com/BurntSushi/toml"
2324
"github.com/chaseadamsio/goorgeous"
24-
toml "github.com/pelletier/go-toml"
2525

2626
"gopkg.in/yaml.v2"
2727
)
@@ -52,13 +52,7 @@ func InterfaceToConfig(in interface{}, mark rune, w io.Writer) error {
5252
return err
5353

5454
case rune(TOMLLead[0]):
55-
tree, err := toml.TreeFromMap(in.(map[string]interface{}))
56-
if err != nil {
57-
return err
58-
}
59-
60-
_, err = tree.WriteTo(w)
61-
return err
55+
return toml.NewEncoder(w).Encode(in)
6256
case rune(JSONLead[0]):
6357
b, err := json.MarshalIndent(in, "", " ")
6458
if err != nil {
@@ -176,14 +170,10 @@ func HandleTOMLMetaData(datum []byte) (interface{}, error) {
176170
m := map[string]interface{}{}
177171
datum = removeTOMLIdentifier(datum)
178172

179-
tree, err := toml.LoadReader(bytes.NewReader(datum))
180-
if err != nil {
181-
return m, err
182-
}
173+
_, err := toml.Decode(string(datum), &m)
183174

184-
m = tree.ToMap()
175+
return m, err
185176

186-
return m, nil
187177
}
188178

189179
// removeTOMLIdentifier removes, if necessary, beginning and ending TOML

0 commit comments

Comments
 (0)