From 0da14a85cc8ea02f0bb38f8b3970052cff195a4e Mon Sep 17 00:00:00 2001 From: Bruno Massa Date: Mon, 3 Jul 2023 20:26:26 -0300 Subject: [PATCH] fix: build output is now, if absent, publish from source --- source/BuildOptions.cs | 2 +- source/IGenerateOptions.cs | 6 +++--- source/Models/Frontmatter.cs | 11 +++++++++-- source/Program.cs | 9 +++++---- source/ServeOptions.cs | 2 +- 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/source/BuildOptions.cs b/source/BuildOptions.cs index 4a7ec02..fc27214 100644 --- a/source/BuildOptions.cs +++ b/source/BuildOptions.cs @@ -9,7 +9,7 @@ public class BuildOptions : IGenerateOptions public string Source { get; set; } = "."; /// - public string Output { get; set; } = "./public"; + public string? Output { get; init; } /// public bool Future { get; set; } diff --git a/source/IGenerateOptions.cs b/source/IGenerateOptions.cs index 152f920..585b749 100644 --- a/source/IGenerateOptions.cs +++ b/source/IGenerateOptions.cs @@ -8,15 +8,15 @@ public interface IGenerateOptions /// /// The path of the source files. /// - string Source { get; set; } + string Source { get; } /// /// The path of the output files. /// - public string Output { get; set; } + public string? Output { get; } /// /// Consider /// - bool Future { get; set; } + bool Future { get; } } \ No newline at end of file diff --git a/source/Models/Frontmatter.cs b/source/Models/Frontmatter.cs index 4de58bb..621f4c2 100644 --- a/source/Models/Frontmatter.cs +++ b/source/Models/Frontmatter.cs @@ -314,8 +314,15 @@ public class Frontmatter : IBaseContent, IParams var permaLink = string.Empty; URLforce ??= URL - ?? (isIndex ? "{{ page.SourcePathDirectory }}" : "{{ page.SourcePathDirectory }}/{{ page.Title }}"); - + ?? (isIndex + ? "{{ page.SourcePathDirectory }}" + : @"{{ page.SourcePathDirectory }}/{%- liquid +if page.Title != '' +echo page.Title +else +echo page.SourceFileNameWithoutExtension +endif +-%}"); try { diff --git a/source/Program.cs b/source/Program.cs index 055f529..87a217a 100644 --- a/source/Program.cs +++ b/source/Program.cs @@ -1,4 +1,5 @@ using System.CommandLine; +using System.IO; using System.Reflection; using System.Threading.Tasks; using Serilog; @@ -50,11 +51,11 @@ public class Program // Shared options between the commands var sourceOption = new Option(new[] { "--source", "-s" }, () => ".", "Source directory path"); - var futureOption = new Option(new[] { "--future", "-f" }, () => false, "Include content with dates in the future"); - var verboseOption = new Option(new[] { "--verbose", "-v" }, () => false, "Verbose output"); + var futureOption = new Option(new[] { "--future", "-f" }, "Include content with dates in the future"); + var verboseOption = new Option(new[] { "--verbose", "-v" }, "Verbose output"); // BuildCommand setup - var buildOutputOption = new Option(new[] { "--output", "-o" }, () => "./public", "Output directory path"); + var buildOutputOption = new Option(new[] { "--output", "-o" }, "Output directory path"); Command buildCommandHandler = new("build", "Builds the site") { @@ -68,7 +69,7 @@ public class Program BuildOptions buildOptions = new() { Source = source, - Output = output, + Output = string.IsNullOrEmpty(output) ? Path.Combine(source, "public") : output, Future = future }; logger = new LoggerConfiguration() diff --git a/source/ServeOptions.cs b/source/ServeOptions.cs index fe9d50d..86169f7 100644 --- a/source/ServeOptions.cs +++ b/source/ServeOptions.cs @@ -9,7 +9,7 @@ public class ServeOptions : IGenerateOptions public string Source { get; set; } = "."; /// - public string Output { get; set; } = "./public"; + public string? Output { get; set; } /// public bool Future { get; set; } -- GitLab