Removing Future Entities
When trying to establish a cadence of posting, a buffer is useful to have to ensure there are enough posts when life throws a curve ball. As a static site generator, Nitride doesn't have automatic publishing but it can control which entities are available based on the NodeTime.Instant
component of that entity by removing ones that happen in the future.
Extensions
When working with removing future, it is helpful to be able to regenerate the site with a future date to see how it looks. This required modifying the module setup (UseTemporal
) in the builder and including the WithDateOptionCommandLineOption()
call.
public static async Task<int> Main(string[] args)
{
NitrideBuilder builder = new NitrideBuilder(args)
.UseTemporal(
config =>
{
config
.WithDateTimeZone("America/Chicago")
.WithDateOptionCommandLineOption();
});
return await builder.RunAsync();
}
This provides a --date
option which defaults to the current moment, but can be used to change the date into the past or future.
Setup
The setup is fairly simple because FilterOutFutureInstant
doesn't have any options.
using MfGames.Nitride.Temporal;
public class SitePipeline : PipelineBase
{
private FilterOutFutureInstant filterOutFutureInstant;
public SitePipeline(FilterOutFutureInstant filterOutFutureInstant)
{
this.filterOutFutureInstant = filterOutFutureInstant;
}
}
Operations
Likewise, since there aren't any options for this, it just has to be added into the pipeline's processing. This assumes that entities have a NodeTime.Instant
component in them; if they don't, then they are ignored.
/// <inheritdoc />
public override IAsyncEnumerable<Entity> RunAsync(
IEnumerable<Entity> entities,
CancellationToken cancellationToken = default
)
{
return entities
.Run(this.filterOutFutureInstant, cancellationToken)
.ToAsyncEnumerable();
}
Metadata
Project
- Project Home
- Documentation
- Repository
- Issues
- Project ID: 01947839-fc77-7f19-8d03-e576f477e15c