summaryrefslogtreecommitdiff
path: root/model/tags.go
diff options
context:
space:
mode:
authorewy <ewy0@protonmail.com>2026-04-14 16:37:17 +0200
committerewy <ewy0@protonmail.com>2026-04-14 16:37:17 +0200
commit45a297a8e526094e8fce6e2c5c0fd89b381d1765 (patch)
tree852ebc3a0112c94dc9726d0b27ab057bf6383660 /model/tags.go
i have to commit at some point!
Diffstat (limited to 'model/tags.go')
-rw-r--r--model/tags.go77
1 files changed, 77 insertions, 0 deletions
diff --git a/model/tags.go b/model/tags.go
new file mode 100644
index 0000000..e3f9f2e
--- /dev/null
+++ b/model/tags.go
@@ -0,0 +1,77 @@
+package model
+
+import (
+ "slices"
+ "strings"
+)
+
+type Tag *string
+type TagAction func(src *Source)
+
+func New(input string) Tag {
+ result := &input
+ TagMap[input] = result
+ TagList = append(TagList, result)
+ return result
+}
+
+var (
+ Here = New("here")
+ Pre = New("pre")
+ Post = New("post")
+ Final = New("final")
+ Hidden = New("hidden")
+ Single = New("single")
+)
+
+var TagList []Tag
+
+var TagMap = map[string]Tag{}
+
+type Tags []Tag
+
+func (t Tags) AnyOf(expected ...Tag) bool {
+ if len(expected) > 1 && len(t) == 0 {
+ return false
+ }
+ if len(expected) == 0 {
+ return true
+ }
+ for _, e := range expected {
+ if slices.Contains(t, e) {
+ return true
+ }
+ }
+ return false
+}
+
+func (t Tags) Has(expected Tag) bool {
+ return slices.Contains(t, expected)
+}
+
+func TagsFromFilename(filename string) Tags {
+ var tags Tags
+ // if hidden
+ if strings.HasPrefix(filename, ".") {
+ filename = strings.TrimPrefix(filename, ".")
+ tags = append(tags, Hidden)
+ }
+
+ parts := strings.Split(filename, ".")
+ if len(parts) == 1 {
+ return nil
+ }
+
+ for _, p := range parts {
+ p = strings.ToLower(p)
+ if TagMap[p] != nil {
+ tags = append(tags, TagMap[p])
+ }
+ }
+
+ return tags
+}
+
+func (t Tags) Visible() bool {
+ return !t.AnyOf(Hidden, Pre, Post, Final)
+}