diff options
| -rw-r--r-- | internal/platforms/platform.go | 7 | ||||
| -rw-r--r-- | internal/schedule/schedule.go | 2 | ||||
| -rw-r--r-- | internal/tags/inline_test.go | 2 | ||||
| -rw-r--r-- | internal/tags/share.go | 27 | ||||
| -rw-r--r-- | internal/tags/share_test.go | 30 |
5 files changed, 60 insertions, 8 deletions
diff --git a/internal/platforms/platform.go b/internal/platforms/platform.go index 99169f1..95cade2 100644 --- a/internal/platforms/platform.go +++ b/internal/platforms/platform.go @@ -22,6 +22,9 @@ var aliases = map[string]string{ "ma": "mastodon", "no": "noop", "noop": "noop", + "snonux": "snonux", + "sno": "snonux", + "sn": "snonux", "xcom": "xcom", "x": "xcom", "twitter": "xcom", @@ -50,6 +53,8 @@ func (p Platform) Post(ctx context.Context, args config.Args, sizeLimit int, en err = linkedin.Post(ctx, args, sizeLimit, en) case "noop": err = noop.Post(ctx, args, sizeLimit, en) + case "snonux": + err = noop.Post(ctx, args, sizeLimit, en) default: err = fmt.Errorf("Platform '%s' (not yet) implemented", p) } @@ -75,7 +80,7 @@ func ExpandAliases(shareTag string) (string, error) { dedup := make(map[string]struct{}, len(aliases)) for _, alias := range parts[1:] { - platformStr, ok := aliases[alias] + platformStr, ok := aliases[strings.ToLower(alias)] if !ok { return "", fmt.Errorf("invalid platform alias '%s' in '%s'", alias, shareTag) } diff --git a/internal/schedule/schedule.go b/internal/schedule/schedule.go index 0e3e8b3..b787b7f 100644 --- a/internal/schedule/schedule.go +++ b/internal/schedule/schedule.go @@ -29,7 +29,7 @@ func Run(args config.Args, platform platforms.Platform) (entry.Entry, error) { } stats.RenderTable(platform) - if platform != "noop" && stats.queued < args.MinQueued { + if platform != "noop" && platform != "snonux" && stats.queued < args.MinQueued { _ = prompt.Acknowledge( fmt.Sprintf("There are only %d messages queued for %s - time to fill it up!", stats.queued, platform), diff --git a/internal/tags/inline_test.go b/internal/tags/inline_test.go index af089ed..0a760b3 100644 --- a/internal/tags/inline_test.go +++ b/internal/tags/inline_test.go @@ -17,6 +17,7 @@ func TestInlineExtractTagsToFilePath(t *testing.T) { "share:li,foo this is the main content": "./gosdir/foo.golang.rox.share:linkedin.foo.extracted.txt", "share:li:ma this is the main content": "./gosdir/foo.golang.rox.share:linkedin:mastodon.extracted.txt", "share:li:ma,now this is the main content": "./gosdir/foo.golang.rox.share:linkedin:mastodon.now.extracted.txt", + "share:sno this is the main content": "./gosdir/foo.golang.rox.share:snonux.extracted.txt", "share,soon this will be shared soon": "./gosdir/foo.golang.rox.share.soon.extracted.txt", } @@ -40,6 +41,7 @@ func TestInlineExtractTagsFromContent(t *testing.T) { "foo.bar,baz blablablabla...": {"foo", "bar", "baz"}, "foo,bar.baz blablablabla...": {"foo", "bar", "baz"}, "share:li this is the main content": {"share:linkedin"}, + "share:sn this is the main content": {"share:snonux"}, "share:li,foo this is the main content": {"share:linkedin", "foo"}, "shar()e:li,foo this is the main content": {"shar()e:li", "foo"}, "share this post": {}, diff --git a/internal/tags/share.go b/internal/tags/share.go index a3d48e5..bc3ddaf 100644 --- a/internal/tags/share.go +++ b/internal/tags/share.go @@ -5,6 +5,7 @@ import ( "strings" "codeberg.org/snonux/gos/internal/config" + "codeberg.org/snonux/gos/internal/platforms" ) // Share tags. @@ -22,23 +23,37 @@ func NewShare(args config.Args, tags map[string]struct{}) (Share, error) { } for _, t := range strings.Split(tag[6:], ":") { if strings.HasPrefix(t, "-") { - s.Excludes = append(s.Excludes, strings.ToLower(t[1:])) + raw := strings.ToLower(t[1:]) + if p, err := platforms.New(raw); err == nil { + raw = p.String() + } + s.Excludes = append(s.Excludes, raw) } else { - s.Includes = append(s.Includes, strings.ToLower(t)) + raw := strings.ToLower(t) + if p, err := platforms.New(raw); err == nil { + raw = p.String() + } + s.Includes = append(s.Includes, raw) } } } - // If there is no share tag, by default include all platforms but "Noop" + // If there is no share tag, by default include all platforms but noop-like + // platforms (Noop, Snonux) that are only queued when explicitly named in share:. if len(s.Includes) == 0 { for platformStr := range args.Platforms { - if slices.Contains(s.Excludes, strings.ToLower(platformStr)) { + p, err := platforms.New(platformStr) + if err != nil { continue } - if platformStr == "Noop" { + name := p.String() + if name == "noop" || name == "snonux" { continue } - s.Includes = append(s.Includes, strings.ToLower(platformStr)) + if slices.Contains(s.Excludes, name) { + continue + } + s.Includes = append(s.Includes, name) } } diff --git a/internal/tags/share_test.go b/internal/tags/share_test.go index f018593..67c41ed 100644 --- a/internal/tags/share_test.go +++ b/internal/tags/share_test.go @@ -56,6 +56,36 @@ func TestSharePositive(t *testing.T) { } } +func TestShareSnonuxDefaultExcluded(t *testing.T) { + args := config.Args{Platforms: map[string]int{ + "mastodon": 500, + "Snonux": 2000, + }} + s, err := NewShare(args, map[string]struct{}{"prio": {}}) + if err != nil { + t.Fatal(err) + } + if slices.Contains(s.Includes, "snonux") { + t.Errorf("snonux should not be in default includes, got %v", s.Includes) + } + if !slices.Contains(s.Includes, "mastodon") { + t.Errorf("expected mastodon in includes, got %v", s.Includes) + } +} + +func TestShareSnonuxExplicitAliases(t *testing.T) { + for _, tag := range []string{"share:snonux", "share:sno", "share:sn"} { + args := config.Args{Platforms: map[string]int{"snonux": 2000}} + s, err := NewShare(args, map[string]struct{}{tag: {}}) + if err != nil { + t.Fatal(tag, err) + } + if !sameElements(s.Includes, []string{"snonux"}) { + t.Errorf("%s: expected includes [snonux], got %v", tag, s.Includes) + } + } +} + func TestShareNegative(t *testing.T) { args := config.Args{Platforms: map[string]int{ string("mastodon"): 100, |
