Skip to content

Commit f02da7f

Browse files
authored
parser: Handle org-mode filetags as slice
This adds support for filetags by slicing them according to [the org mode tag specification](https://orgmode.org/guide/Tags.html). Can be used to create taxonomies based on org-mode tags
1 parent 22ee091 commit f02da7f

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

parser/metadecoders/decoder.go

+4
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,10 @@ func (d Decoder) unmarshalORG(data []byte, v any) error {
251251
frontMatter[k[:len(k)-2]] = strings.Fields(v)
252252
} else if strings.Contains(v, "\n") {
253253
frontMatter[k] = strings.Split(v, "\n")
254+
} else if k == "filetags" {
255+
trimmed := strings.TrimPrefix(v, ":")
256+
trimmed = strings.TrimSuffix(trimmed, ":")
257+
frontMatter[k] = strings.Split(trimmed, ":")
254258
} else if k == "date" || k == "lastmod" || k == "publishdate" || k == "expirydate" {
255259
frontMatter[k] = parseORGDate(v)
256260
} else {

parser/metadecoders/decoder_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ func TestUnmarshalToInterface(t *testing.T) {
131131
{[]byte("#+a: foo bar\n#+a: baz"), ORG, map[string]any{"a": []string{string("foo bar"), string("baz")}}},
132132
{[]byte(`#+DATE: <2020-06-26 Fri>`), ORG, map[string]any{"date": "2020-06-26"}},
133133
{[]byte(`#+LASTMOD: <2020-06-26 Fri>`), ORG, map[string]any{"lastmod": "2020-06-26"}},
134+
{[]byte(`#+FILETAGS: :work:`), ORG, map[string]any{"filetags": []string{"work"}}},
135+
{[]byte(`#+FILETAGS: :work:fun:`), ORG, map[string]any{"filetags": []string{"work", "fun"}}},
134136
{[]byte(`#+PUBLISHDATE: <2020-06-26 Fri>`), ORG, map[string]any{"publishdate": "2020-06-26"}},
135137
{[]byte(`#+EXPIRYDATE: <2020-06-26 Fri>`), ORG, map[string]any{"expirydate": "2020-06-26"}},
136138
{[]byte(`a = "b"`), TOML, expect},

0 commit comments

Comments
 (0)