shithub: hugo

Download patch

ref: c66dc6c74fa3bbe308ccaade8c76071b49908129
parent: 127d5feb32b466c4a0035e81f86684920dd88cfe
author: Sebastian Boehm <sebastian@sometimesfood.org>
date: Fri Jun 26 19:52:12 EDT 2020

Add support for native Org dates in frontmatter

--- a/parser/metadecoders/decoder.go
+++ b/parser/metadecoders/decoder.go
@@ -18,6 +18,7 @@
 	"encoding/csv"
 	"encoding/json"
 	"fmt"
+	"regexp"
 	"strings"
 
 	"github.com/gohugoio/hugo/common/herrors"
@@ -203,6 +204,14 @@
 
 }
 
+func parseORGDate(s string) string {
+	r := regexp.MustCompile(`[<\[](\d{4}-\d{2}-\d{2}) .*[>\]]`)
+	if m := r.FindStringSubmatch(s); m != nil {
+		return m[1]
+	}
+	return s
+}
+
 func (d Decoder) unmarshalORG(data []byte, v interface{}) error {
 	config := org.New()
 	config.Log = jww.WARN
@@ -218,6 +227,8 @@
 		} else if k == "tags" || k == "categories" || k == "aliases" {
 			jww.WARN.Printf("Please use '#+%s[]:' notation, automatic conversion is deprecated.", k)
 			frontMatter[k] = strings.Fields(v)
+		} else if k == "date" {
+			frontMatter[k] = parseORGDate(v)
 		} else {
 			frontMatter[k] = v
 		}
--- a/parser/metadecoders/decoder_test.go
+++ b/parser/metadecoders/decoder_test.go
@@ -69,6 +69,7 @@
 		{`[ "Brecker", "Blake", "Redman" ]`, JSON, []interface{}{"Brecker", "Blake", "Redman"}},
 		{`{ "a": "b" }`, JSON, expect},
 		{`#+a: b`, ORG, expect},
+		{`#+DATE: <2020-06-26 Fri>`, ORG, map[string]interface{}{"date": "2020-06-26"}},
 		{`a = "b"`, TOML, expect},
 		{`a: "b"`, YAML, expect},
 		{`a,b,c`, CSV, [][]string{{"a", "b", "c"}}},