]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
parser/metadecoders: Accumulate org keywords into arrays
authorAugust Feng <augustfengd@gmail.com>
Sun, 26 Nov 2023 03:33:02 +0000 (22:33 -0500)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 25 Jan 2024 18:34:12 +0000 (19:34 +0100)
Closes #11743

docs/content/en/content-management/front-matter.md
parser/metadecoders/decoder.go
parser/metadecoders/decoder_test.go

index dba67ba10734346df9e044bb2559e3f27995b5e0..7593fb759714952f69f1072088b19993716e9919 100644 (file)
@@ -31,7 +31,7 @@ JSON
 
 ORG
 : a group of Org mode keywords in the format '`#+KEY: VALUE`'. Any line that does not start with `#+` ends the front matter section.
-  Keyword values can be either strings (`#+KEY: VALUE`) or a whitespace separated list of strings (`#+KEY[]: VALUE_1 VALUE_2`).
+  Array values can either be separated into multiple lines (`#+KEY: VALUE_1` and `#+KEY: VALUE_2`) or a whitespace separated list of strings (`#+KEY[]: VALUE_1 VALUE_2`).
 
 ### Example
 
index 35368e5a531e624cb4de18c65bcfc8300e26946e..8d93d86a0331dea0299be1d1b9d55399219c357f 100644 (file)
@@ -249,9 +249,8 @@ func (d Decoder) unmarshalORG(data []byte, v any) error {
                k = strings.ToLower(k)
                if strings.HasSuffix(k, "[]") {
                        frontMatter[k[:len(k)-2]] = strings.Fields(v)
-               } else if k == "tags" || k == "categories" || k == "aliases" {
-                       log.Printf("warn: Please use '#+%s[]:' notation, automatic conversion is deprecated.", k)
-                       frontMatter[k] = strings.Fields(v)
+               } else if strings.Contains(v, "\n") {
+                       frontMatter[k] = strings.Split(v, "\n")
                } else if k == "date" || k == "lastmod" || k == "publishdate" || k == "expirydate" {
                        frontMatter[k] = parseORGDate(v)
                } else {
index ff6f8c226a0ab2a024c69484a62446dc78147ef4..48def7d124407d4449928798df0eca125deb4ffe 100644 (file)
@@ -125,6 +125,7 @@ func TestUnmarshalToInterface(t *testing.T) {
                {[]byte(``), JSON, map[string]any{}},
                {[]byte(nil), JSON, map[string]any{}},
                {[]byte(`#+a: b`), ORG, expect},
+               {[]byte("#+a: foo bar\n#+a: baz"), ORG, map[string]any{"a": []string{string("foo bar"), string("baz")}}},
                {[]byte(`#+DATE: <2020-06-26 Fri>`), ORG, map[string]any{"date": "2020-06-26"}},
                {[]byte(`#+LASTMOD: <2020-06-26 Fri>`), ORG, map[string]any{"lastmod": "2020-06-26"}},
                {[]byte(`#+PUBLISHDATE: <2020-06-26 Fri>`), ORG, map[string]any{"publishdate": "2020-06-26"}},