aboutsummaryrefslogtreecommitdiffhomepage
path: root/parser
diff options
context:
space:
mode:
authorNiklas Fasching <[email protected]>2019-06-04 12:21:25 +0200
committerBjørn Erik Pedersen <[email protected]>2019-06-08 10:13:00 +0200
commitb6867bf8068fcaaddf1cb7478f4d52a9c1be1411 (patch)
tree2229d8788d26498cfd569904f442a0510e490b2c /parser
parent9df57154ee3e3185d024bfe376101b404d8b7cc4 (diff)
downloadhugo-b6867bf8068fcaaddf1cb7478f4d52a9c1be1411.tar.gz
hugo-b6867bf8068fcaaddf1cb7478f4d52a9c1be1411.zip
Improve Org mode support: Replace goorgeous with go-org
Sadly, goorgeous has not been updated in over a year and still has a lot of open issues (e.g. no support for nested lists). go-org fixes most of those issues and supports a larger subset of Org mode syntax.
Diffstat (limited to 'parser')
-rw-r--r--parser/metadecoders/decoder.go39
1 files changed, 28 insertions, 11 deletions
diff --git a/parser/metadecoders/decoder.go b/parser/metadecoders/decoder.go
index b2d8307b6..af2e19f8f 100644
--- a/parser/metadecoders/decoder.go
+++ b/parser/metadecoders/decoder.go
@@ -21,12 +21,13 @@ import (
"strings"
"github.com/gohugoio/hugo/common/herrors"
+ "github.com/niklasfasching/go-org/org"
"github.com/BurntSushi/toml"
- "github.com/chaseadamsio/goorgeous"
"github.com/pkg/errors"
"github.com/spf13/afero"
"github.com/spf13/cast"
+ jww "github.com/spf13/jwalterweatherman"
yaml "gopkg.in/yaml.v2"
)
@@ -106,16 +107,7 @@ func (d Decoder) unmarshal(data []byte, f Format, v interface{}) error {
switch f {
case ORG:
- vv, err := goorgeous.OrgHeaders(data)
- if err != nil {
- return toFileError(f, errors.Wrap(err, "failed to unmarshal ORG headers"))
- }
- switch v.(type) {
- case *map[string]interface{}:
- *v.(*map[string]interface{}) = vv
- default:
- *v.(*interface{}) = vv
- }
+ err = d.unmarshalORG(data, v)
case JSON:
err = json.Unmarshal(data, v)
case TOML:
@@ -185,6 +177,31 @@ func (d Decoder) unmarshalCSV(data []byte, v interface{}) error {
}
+func (d Decoder) unmarshalORG(data []byte, v interface{}) error {
+ config := org.New()
+ config.Log = jww.WARN
+ document := config.Parse(bytes.NewReader(data), "")
+ if document.Error != nil {
+ return document.Error
+ }
+ frontMatter := make(map[string]interface{}, len(document.BufferSettings))
+ for k, v := range document.BufferSettings {
+ k = strings.ToLower(k)
+ if k == "tags" || k == "categories" || k == "aliases" {
+ frontMatter[k] = strings.Fields(v)
+ } else {
+ frontMatter[k] = v
+ }
+ }
+ switch v.(type) {
+ case *map[string]interface{}:
+ *v.(*map[string]interface{}) = frontMatter
+ default:
+ *v.(*interface{}) = frontMatter
+ }
+ return nil
+}
+
func toFileError(f Format, err error) error {
return herrors.ToFileError(string(f), err)
}