Skip to content

Commit cb0e05a

Browse files
Refactor content formatters to better support short form content required by Bluesky (#224)
1 parent 6380023 commit cb0e05a

9 files changed

+74
-11
lines changed

Solutions/Stacker.Cli/Commands/BlueskyBufferCommand.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public BlueskyBufferCommand(IContentTasks contentTasks)
2929
/// <inheritdoc/>
3030
public override async Task<int> ExecuteAsync([NotNull] CommandContext context, [NotNull] Settings settings)
3131
{
32-
await this.contentTasks.BufferContentItemsAsync<TweetFormatter>(
32+
await this.contentTasks.BufferContentItemsAsync<BlueskyFormatter>(
3333
settings.ContentFilePath,
3434
settings.ContentUri,
3535
this.profilePrefix,

Solutions/Stacker.Cli/Commands/MastodonBufferCommand.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public MastodonBufferCommand(IContentTasks contentTasks)
3030
/// <inheritdoc/>
3131
public override async Task<int> ExecuteAsync([NotNull] CommandContext context, [NotNull] Settings settings)
3232
{
33-
await this.contentTasks.BufferContentItemsAsync<TweetFormatter>(
33+
await this.contentTasks.BufferContentItemsAsync<MastodonFormatter>(
3434
settings.ContentFilePath,
3535
settings.ContentUri,
3636
this.profilePrefix,

Solutions/Stacker.Cli/Commands/TwitterBufferCommand.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public TwitterBufferCommand(IContentTasks contentTasks)
3030
/// <inheritdoc/>
3131
public override async Task<int> ExecuteAsync([NotNull] CommandContext context, [NotNull] Settings settings)
3232
{
33-
await this.contentTasks.BufferContentItemsAsync<TweetFormatter>(
33+
await this.contentTasks.BufferContentItemsAsync<TwitterFormatter>(
3434
settings.ContentFilePath,
3535
settings.ContentUri,
3636
this.profilePrefix,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// <copyright file="BlueskyFormatter.cs" company="Endjin Limited">
2+
// Copyright (c) Endjin Limited. All rights reserved.
3+
// </copyright>
4+
5+
using Stacker.Cli.Contracts.Formatters;
6+
7+
namespace Stacker.Cli.Formatters;
8+
9+
public class BlueskyFormatter : ShortFormContentFormatter, IContentFormatter
10+
{
11+
private const int MaxContentLength = 300;
12+
13+
public BlueskyFormatter()
14+
: base(MaxContentLength, "bluesky")
15+
{
16+
}
17+
}

Solutions/Stacker.Cli/Formatters/LongFormContentFormatter.cs

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Copyright (c) Endjin Limited. All rights reserved.
33
// </copyright>
44

5-
using System;
65
using System.Collections.Generic;
76
using System.Linq;
87
using System.Text;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// <copyright file="MastodonFormatter.cs" company="Endjin Limited">
2+
// Copyright (c) Endjin Limited. All rights reserved.
3+
// </copyright>
4+
5+
using Stacker.Cli.Contracts.Formatters;
6+
7+
namespace Stacker.Cli.Formatters;
8+
9+
public class MastodonFormatter : ShortFormContentFormatter, IContentFormatter
10+
{
11+
private const int MaxContentLength = 500;
12+
13+
public MastodonFormatter()
14+
: base(MaxContentLength, "mastodon")
15+
{
16+
}
17+
}

Solutions/Stacker.Cli/Formatters/TweetFormatter.cs Solutions/Stacker.Cli/Formatters/ShortFormContentFormatter.cs

+19-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// <copyright file="TweetFormatter.cs" company="Endjin Limited">
1+
// <copyright file="ShortFormContentFormatter.cs" company="Endjin Limited">
22
// Copyright (c) Endjin Limited. All rights reserved.
33
// </copyright>
44

@@ -12,14 +12,20 @@
1212

1313
namespace Stacker.Cli.Formatters;
1414

15-
public class TweetFormatter : IContentFormatter
15+
public class ShortFormContentFormatter : IContentFormatter
1616
{
17-
private const int MaxContentLength = 280;
18-
private readonly string campaignSource = "twitter";
17+
private readonly int maxContentLength;
18+
private readonly string campaignSource;
19+
20+
public ShortFormContentFormatter(int maxContentLength, string campaignSource)
21+
{
22+
this.campaignSource = campaignSource;
23+
this.maxContentLength = maxContentLength;
24+
}
1925

2026
public IEnumerable<string> Format(string campaignMedium, string campaignName, IEnumerable<ContentItem> feedItems, StackerSettings settings)
2127
{
22-
List<string> tweets = new();
28+
List<string> tweets = [];
2329
StringBuilder content = new();
2430
StringBuilder campaignTracking = new();
2531

@@ -54,6 +60,13 @@ public IEnumerable<string> Format(string campaignMedium, string campaignName, IE
5460
}
5561
}
5662

63+
// If we don't find a match from our users, just use the display name
64+
if (match is null)
65+
{
66+
content.Append(" by ");
67+
content.Append(item.Author.DisplayName);
68+
}
69+
5770
if (item?.Tags != null && item.Tags.Any())
5871
{
5972
int tweetLength = content.Length + campaignTracking.Length + 1; // 1 = extra space before link
@@ -62,7 +75,7 @@ public IEnumerable<string> Format(string campaignMedium, string campaignName, IE
6275
foreach (string tag in item.Tags)
6376
{
6477
tweetLength += tag.Length + 2; // 2 Offset = Space + #
65-
if (tweetLength <= MaxContentLength)
78+
if (tweetLength <= this.maxContentLength)
6679
{
6780
tagsToInclude++;
6881
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// <copyright file="TwitterFormatter.cs" company="Endjin Limited">
2+
// Copyright (c) Endjin Limited. All rights reserved.
3+
// </copyright>
4+
5+
using Stacker.Cli.Contracts.Formatters;
6+
7+
namespace Stacker.Cli.Formatters;
8+
9+
public class TwitterFormatter : ShortFormContentFormatter, IContentFormatter
10+
{
11+
private const int MaxContentLength = 280;
12+
13+
public TwitterFormatter()
14+
: base(MaxContentLength, "twitter")
15+
{
16+
}
17+
}

Solutions/Stacker.Cli/Properties/launchSettings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"profiles": {
33
"Endjin.Stacker.Cli": {
44
"commandName": "Project",
5-
"commandLineArgs": "wordpress export markdown"
5+
"commandLineArgs": "bluesky buffer -c \"C:\\Temp\\478.json\" -n azureweekly"
66
}
77
}
88
}

0 commit comments

Comments
 (0)