diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-12-23 10:40:32 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-12-23 16:33:21 +0100 |
commit | a5744697971d296eb973e04e4259fe9e516b908f (patch) | |
tree | 488ed37ebfc8916b5cfcdaade249884aec7105c3 /hugolib | |
parent | 822dc627a1cfdf1f97882f27761675ac6ace7669 (diff) |
Add CSV support to transform.Unmarshal
Fixes #5555
Diffstat (limited to 'hugolib')
-rw-r--r-- | hugolib/config.go | 2 | ||||
-rw-r--r-- | hugolib/page_content.go | 2 | ||||
-rw-r--r-- | hugolib/resource_chain_test.go | 10 | ||||
-rw-r--r-- | hugolib/site.go | 2 |
4 files changed, 12 insertions, 4 deletions
diff --git a/hugolib/config.go b/hugolib/config.go index 3a452d5fd..f71881e25 100644 --- a/hugolib/config.go +++ b/hugolib/config.go @@ -285,7 +285,7 @@ func (l configLoader) loadConfigFromConfigDir(v *viper.Viper) ([]string, error) name := helpers.Filename(filepath.Base(path)) - item, err := metadecoders.UnmarshalFileToMap(sourceFs, path) + item, err := metadecoders.Default.UnmarshalFileToMap(sourceFs, path) if err != nil { return l.wrapFileError(err, path) } diff --git a/hugolib/page_content.go b/hugolib/page_content.go index af13d8a38..924400aea 100644 --- a/hugolib/page_content.go +++ b/hugolib/page_content.go @@ -91,7 +91,7 @@ Loop: result.Write(it.Val) case it.IsFrontMatter(): f := metadecoders.FormatFromFrontMatterType(it.Type) - m, err := metadecoders.UnmarshalToMap(it.Val, f) + m, err := metadecoders.Default.UnmarshalToMap(it.Val, f) if err != nil { if fe, ok := err.(herrors.FileError); ok { return herrors.ToFileErrorWithOffset(fe, iter.LineNumber()-1) diff --git a/hugolib/resource_chain_test.go b/hugolib/resource_chain_test.go index 74129dc17..e3123952d 100644 --- a/hugolib/resource_chain_test.go +++ b/hugolib/resource_chain_test.go @@ -342,11 +342,19 @@ Publish 2: {{ $cssPublish2.Permalink }} {"unmarshal", func() bool { return true }, func(b *sitesBuilder) { b.WithTemplates("home.html", ` {{ $toml := "slogan = \"Hugo Rocks!\"" | resources.FromString "slogan.toml" | transform.Unmarshal }} +{{ $csv1 := "\"Hugo Rocks\",\"Hugo is Fast!\"" | resources.FromString "slogans.csv" | transform.Unmarshal }} +{{ $csv2 := "a;b;c" | resources.FromString "abc.csv" | transform.Unmarshal (dict "csvComma" ";") }} + Slogan: {{ $toml.slogan }} +CSV1: {{ $csv1 }} {{ len (index $csv1 0) }} +CSV2: {{ $csv2 }} `) }, func(b *sitesBuilder) { - b.AssertFileContent("public/index.html", `Slogan: Hugo Rocks!`) + b.AssertFileContent("public/index.html", + `Slogan: Hugo Rocks!`, + `[[Hugo Rocks Hugo is Fast!]] 2`, + ) }}, {"template", func() bool { return true }, func(b *sitesBuilder) {}, func(b *sitesBuilder) { diff --git a/hugolib/site.go b/hugolib/site.go index 2fd9f17ee..c6d203d8a 100644 --- a/hugolib/site.go +++ b/hugolib/site.go @@ -1014,7 +1014,7 @@ func (s *Site) readData(f source.ReadableFile) (interface{}, error) { content := helpers.ReaderToBytes(file) format := metadecoders.FormatFromString(f.Extension()) - return metadecoders.Unmarshal(content, format) + return metadecoders.Default.Unmarshal(content, format) } func (s *Site) readDataFromSourceFS() error { |