Skip to content

Commit

Permalink
metadecoders: Add support for native org dates in frontmatter
Browse files Browse the repository at this point in the history
PR #7433 added support for Org timestamps for the DATE header. This PR widens the support with additional front matter headers LASTMOD, PUBLISHDATE and EXPIRYDATE.

Fixes #8536
  • Loading branch information
johannesengl authored and bep committed Mar 6, 2023
1 parent 32ea40a commit bdbfacb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion parser/metadecoders/decoder.go
Expand Up @@ -244,7 +244,7 @@ func (d Decoder) unmarshalORG(data []byte, v any) error {
} 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" {
} else if k == "date" || k == "lastmod" || k == "publishdate" || k == "expirydate" {
frontMatter[k] = parseORGDate(v)
} else {
frontMatter[k] = v
Expand Down
3 changes: 3 additions & 0 deletions parser/metadecoders/decoder_test.go
Expand Up @@ -126,6 +126,9 @@ func TestUnmarshalToInterface(t *testing.T) {
{[]byte(nil), JSON, map[string]any{}},
{[]byte(`#+a: b`), ORG, expect},
{[]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"}},
{[]byte(`#+EXPIRYDATE: <2020-06-26 Fri>`), ORG, map[string]any{"expirydate": "2020-06-26"}},
{[]byte(`a = "b"`), TOML, expect},
{[]byte(`a: "b"`), YAML, expect},
{[]byte(`<root><a>b</a></root>`), XML, expect},
Expand Down

0 comments on commit bdbfacb

Please sign in to comment.