Skip to content

Commit 1b187fa

Browse files
FIx tag processing logic. (#202)
1 parent 59c7c1c commit 1b187fa

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

Solutions/Stacker.Cli/Domain/Universal/ContentItem.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class ContentItem
2020

2121
public string Id { get; internal set; }
2222

23-
public bool? Promote { get; internal set; }
23+
public bool? Promote { get; set; }
2424

2525
public DateTimeOffset? PromoteUntil { get; set; }
2626

@@ -36,7 +36,7 @@ public string CleanSlug
3636
}
3737
}
3838

39-
public string Status { get; internal set; }
39+
public string Status { get; set; }
4040

4141
public List<string> Tags { get; set; }
4242

Solutions/Stacker.Cli/Formatters/LongFormContentFormatter.cs

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

5+
using System;
56
using System.Collections.Generic;
67
using System.Linq;
78
using System.Text;
@@ -50,9 +51,7 @@ public IEnumerable<string> Format(string campaignMedium, string campaignName, IE
5051
int contentLength = content.Length + campaignTracking.Length + 1; // 1 = extra space before link
5152
int tagsToInclude = 0;
5253

53-
item.Tags = item.Tags.Except(settings.ExcludedTags).OrderByDescending(word => settings.PriorityTags.IndexOf(word)).ToList();
54-
55-
foreach (string tag in item.Tags.Distinct())
54+
foreach (string tag in item.Tags)
5655
{
5756
contentLength += tag.Length + 2; // 2 Offset = Space + #
5857
if (contentLength <= this.maxContentLength)

Solutions/Stacker.Cli/Formatters/TweetFormatter.cs

+2-4
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ public IEnumerable<string> Format(string campaignMedium, string campaignName, IE
5959
int tweetLength = content.Length + campaignTracking.Length + 1; // 1 = extra space before link
6060
int tagsToInclude = 0;
6161

62-
item.Tags = item.Tags.Except(settings.ExcludedTags).OrderByDescending(word => settings.PriorityTags.IndexOf(word)).ToList();
63-
64-
foreach (string tag in item.Tags.Distinct())
62+
foreach (string tag in item.Tags)
6563
{
6664
tweetLength += tag.Length + 2; // 2 Offset = Space + #
6765
if (tweetLength <= MaxContentLength)
@@ -74,7 +72,7 @@ public IEnumerable<string> Format(string campaignMedium, string campaignName, IE
7472
}
7573
}
7674

77-
foreach (string tag in item.Tags.Distinct().Take(tagsToInclude))
75+
foreach (string tag in item.Tags.Take(tagsToInclude))
7876
{
7977
content.Append(" #");
8078
content.Append(tag);

Solutions/Stacker.Cli/Tasks/ContentTasks.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ public async Task<IEnumerable<ContentItem>> LoadContentItemsAsync(
9797

9898
List<ContentItem> content = JsonSerializer.Deserialize<List<ContentItem>>(fileContent);
9999

100+
content = content.Where(p => p.Promote is true).ToList();
101+
100102
if (publicationPeriod != PublicationPeriod.None)
101103
{
102104
AnsiConsole.MarkupLineInterpolated($"[yellow1]Publication Period:[/] {publicationPeriod}");
@@ -138,12 +140,14 @@ public async Task<IEnumerable<ContentItem>> LoadContentItemsAsync(
138140

139141
foreach (ContentItem contentItem in content)
140142
{
143+
contentItem.Tags = contentItem.Tags.Except(this.settings.ExcludedTags, StringComparer.InvariantCultureIgnoreCase).ToList();
144+
141145
// Use TagAliases to convert tags into their canonical form.
142146
contentItem.Tags = contentItem.Tags?.Select(tag =>
143147
{
144148
TagAliases matchedAlias = this.settings.TagAliases.FirstOrDefault(alias => alias.Aliases.Any(a => a == tag));
145149
return matchedAlias != null ? matchedAlias.Tag : tag.Replace("-", " ").Replace(" ", string.Empty);
146-
}).ToList();
150+
}).Distinct().OrderByDescending(word => this.settings.PriorityTags.IndexOf(word)).ToList();
147151
}
148152

149153
// Sort so that content with the shortest lifespan are first.

0 commit comments

Comments
 (0)