From 94801d95d16371b99abda742a35fd57c4e2be123 Mon Sep 17 00:00:00 2001 From: Bruno Massa Date: Thu, 13 Jul 2023 02:29:15 -0300 Subject: [PATCH] feat: expired command line to allow expired pages --- .../CommandLineOptions/GenerateOptions.cs | 3 +++ .../CommandLineOptions/IGenerateOptions.cs | 7 ++++++- source/Models/Site.cs | 3 ++- source/Program.cs | 17 +++++++++++------ 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/source/Models/CommandLineOptions/GenerateOptions.cs b/source/Models/CommandLineOptions/GenerateOptions.cs index d14eba2..eb50030 100644 --- a/source/Models/CommandLineOptions/GenerateOptions.cs +++ b/source/Models/CommandLineOptions/GenerateOptions.cs @@ -10,4 +10,7 @@ internal class GenerateOptions : IGenerateOptions /// public bool Future { get; init; } + + /// + public bool Expired { get; init; } } diff --git a/source/Models/CommandLineOptions/IGenerateOptions.cs b/source/Models/CommandLineOptions/IGenerateOptions.cs index 472bb54..74e249a 100644 --- a/source/Models/CommandLineOptions/IGenerateOptions.cs +++ b/source/Models/CommandLineOptions/IGenerateOptions.cs @@ -11,7 +11,12 @@ public interface IGenerateOptions string Source { get; } /// - /// Consider + /// Consider future content /// bool Future { get; } + + /// + /// Consider expired content + /// + bool Expired { get; } } \ No newline at end of file diff --git a/source/Models/Site.cs b/source/Models/Site.cs index 65a517d..f2e353d 100644 --- a/source/Models/Site.cs +++ b/source/Models/Site.cs @@ -411,7 +411,8 @@ internal class Site : ISite { throw new ArgumentNullException(nameof(frontMatter)); } - return !IsDateExpired(frontMatter) && (IsDatePublishable(frontMatter) || (options?.Future ?? false)); + return (!IsDateExpired(frontMatter) || (options?.Expired ?? false)) + && (IsDatePublishable(frontMatter) || (options?.Future ?? false)); } /// diff --git a/source/Program.cs b/source/Program.cs index cabc01a..59e04c3 100644 --- a/source/Program.cs +++ b/source/Program.cs @@ -53,6 +53,7 @@ internal class Program // Shared options between the commands var sourceOption = new Option(new[] { "--source", "-s" }, () => ".", "Source directory path"); var futureOption = new Option(new[] { "--future", "-f" }, "Include content with dates in the future"); + var expiredOption = new Option(new[] { "--expired", "-e" }, "Include content with ExpiredDate dates from the past"); var verboseOption = new Option(new[] { "--verbose", "-v" }, "Verbose output"); // BuildCommand setup @@ -63,9 +64,10 @@ internal class Program sourceOption, buildOutputOption, futureOption, + expiredOption, verboseOption }; - buildCommandHandler.SetHandler((source, output, future, verbose) => + buildCommandHandler.SetHandler((source, output, future, expired, verbose) => { logger = CreateLogger(verbose); @@ -73,34 +75,37 @@ internal class Program source: source, output: output) { - Future = future + Future = future, + Expired = expired }; _ = new BuildCommand(buildOptions, logger); }, - sourceOption, buildOutputOption, futureOption, verboseOption); + sourceOption, buildOutputOption, futureOption, expiredOption, verboseOption); // ServerCommand setup Command serveCommandHandler = new("serve", "Starts the server") { sourceOption, futureOption, + expiredOption, verboseOption }; - serveCommandHandler.SetHandler(async (source, future, verbose) => + serveCommandHandler.SetHandler(async (source, future, expired, verbose) => { logger = CreateLogger(verbose); ServeOptions serverOptions = new() { Source = source, - Future = future + Future = future, + Expired = expired }; var serveCommand = new ServeCommand(serverOptions, logger, new SourceFileWatcher()); await serveCommand.RunServer(); await Task.Delay(-1); // Wait forever. }, - sourceOption, futureOption, verboseOption); + sourceOption, futureOption, expiredOption, verboseOption); RootCommand rootCommand = new("SuCoS commands") { -- GitLab