Skip to content

Commit

Permalink
Add support for promote properties to be nullable - i.e. promote item…
Browse files Browse the repository at this point in the history
…s without an end date (fully evergreen) (#200)
  • Loading branch information
HowardvanRooijen authored Nov 12, 2023
1 parent 6ad8788 commit b66d533
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 14 deletions.
4 changes: 2 additions & 2 deletions Solutions/Stacker.Cli/Domain/Universal/ContentItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ public class ContentItem

public string Id { get; internal set; }

public bool Promote { get; internal set; }
public bool? Promote { get; internal set; }

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

public DateTimeOffset PublishedOn { get; set; }

Expand Down
9 changes: 1 addition & 8 deletions Solutions/Stacker.Cli/Domain/WordPress/BlogSite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -350,14 +350,7 @@ private void ParseStackerPromote(XElement metaKeyElement, Post post)
{
XElement promoteUntilElement = metaKeyElement.NextNode as XElement;

if (DateTimeOffset.TryParse(promoteUntilElement?.Value, out DateTimeOffset promoteUntil))
{
post.PromoteUntil = promoteUntil;
}
else
{
post.PromoteUntil = DateTimeOffset.MaxValue;
}
post.PromoteUntil = DateTimeOffset.TryParse(promoteUntilElement?.Value, out DateTimeOffset promoteUntil) ? promoteUntil : DateTimeOffset.MaxValue;
}
}
catch (Exception)
Expand Down
4 changes: 2 additions & 2 deletions Solutions/Stacker.Cli/Domain/WordPress/Post.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public Post()

public Dictionary<string, string> MetaData { get; set; }

public bool Promote { get; set; }
public bool? Promote { get; set; }

public DateTimeOffset PromoteUntil { get; set; } = DateTimeOffset.MaxValue;
public DateTimeOffset? PromoteUntil { get; set; } = DateTimeOffset.MaxValue;

public DateTimeOffset PublishedAtUtc { get; set; }

Expand Down
2 changes: 1 addition & 1 deletion Solutions/Stacker.Cli/Domain/WordPress/PostExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static class PostExtensions
{
public static IEnumerable<Post> FilterByPromotable(this IEnumerable<Post> posts)
{
return posts.Where(p => (p.Promote && p.PromoteUntil == DateTimeOffset.MinValue) || (p.Promote && p.PromoteUntil > DateTimeOffset.Now));
return posts.Where(p => (p.Promote is not null && p.Promote.Value && p.PromoteUntil == DateTimeOffset.MinValue) || (p.Promote is not null && p.Promote.Value && p.PromoteUntil > DateTimeOffset.Now));
}

public static IEnumerable<Post> FilterByValid(this IEnumerable<Post> posts, StackerSettings settings)
Expand Down
2 changes: 1 addition & 1 deletion Solutions/Stacker.Cli/Tasks/ContentTasks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public async Task<IEnumerable<ContentItem>> LoadContentItemsAsync(
{
string fileContent = string.Empty;

if (contentUri is not null || !string.IsNullOrEmpty(contentUri.AbsoluteUri))
if (contentUri is not null && !string.IsNullOrEmpty(contentUri.AbsoluteUri))
{
using HttpClient client = this.httpClientFactory.CreateClient();
fileContent = await client.GetStringAsync(contentUri).ConfigureAwait(false);
Expand Down

0 comments on commit b66d533

Please sign in to comment.