Skip to content

Commit bc31072

Browse files
committed
Enhance error handling and tag processing
- Updated `ContentIndexBuilder` to correctly handle `page.Tags`. - Added `ContinueOnError` and `Arguments` properties in `GeneratorOptions`. - Simplified error handling in `SiteGenerator` using `options.ContinueOnError`. - Removed `continueOnError` parameter from `BakeContent` method. - Updated `Program` to initialize `ContinueOnError` from command-line arguments.
1 parent 6f8ec3a commit bc31072

File tree

4 files changed

+8
-10
lines changed

4 files changed

+8
-10
lines changed

src/Blake.BuildTools/Generator/ContentIndexBuilder.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ public static void WriteIndex(string outputPath, List<PageModel> allPages, bool
1818

1919
foreach (var page in allPages)
2020
{
21-
var tags = page.Tags ?? [];
22-
2321
try
2422
{
2523
sb.AppendLine(" new PageModel");
@@ -33,10 +31,10 @@ public static void WriteIndex(string outputPath, List<PageModel> allPages, bool
3331
$" Date = new DateTime({page.Date.Value.Year}, {page.Date.Value.Month}, {page.Date.Value.Day}),");
3432
sb.AppendLine($" Draft = {page.Draft.ToString().ToLowerInvariant()},");
3533
sb.AppendLine($" IconIdentifier = @\"{page.IconIdentifier}\",");
36-
if (tags.Count > 0)
34+
if (page.Tags.Count > 0)
3735
{
3836
sb.AppendLine(
39-
$" Tags = new List<string> {{ {string.Join(", ", tags.Select(t => $"\"{t}\""))} }},");
37+
$" Tags = new List<string> {{ {string.Join(", ", page.Tags.Select(t => $"\"{t}\""))} }},");
4038
}
4139
else
4240
{

src/Blake.BuildTools/Generator/GeneratorOptions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,7 @@ internal class GenerationOptions
1212

1313
public bool Clean { get; init; } = false;
1414

15+
public bool ContinueOnError { get; init; } = false;
16+
1517
public string[] Arguments { get; init; } = [];
1618
}

src/Blake.BuildTools/Generator/SiteGenerator.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ public static async Task BuildAsync(GenerationOptions options, ILogger logger, C
1515
ProjectPath = Directory.GetCurrentDirectory(),
1616
OutputPath = Path.Combine(Directory.GetCurrentDirectory(), ".generated"),
1717
};
18-
19-
var continueOnError = options.Arguments.Contains("--continueOnError") || options.Arguments.Contains("-ce");
2018

2119
logger.LogInformation("🔧 Building site from project path: {OptionsProjectPath}", options.ProjectPath);
2220
logger.LogInformation("📂 Output path: {OptionsOutputPath}", options.OutputPath);
@@ -70,7 +68,7 @@ public static async Task BuildAsync(GenerationOptions options, ILogger logger, C
7068
logger.LogDebug("No plugins loaded.");
7169
}
7270

73-
await BakeContent(context, options, continueOnError, logger, cancellationToken);
71+
await BakeContent(context, options, logger, cancellationToken);
7472

7573
// Run AfterBakeAsync for each plugin
7674
if (plugins.Count > 0)
@@ -104,7 +102,7 @@ public static async Task BuildAsync(GenerationOptions options, ILogger logger, C
104102
}
105103

106104
// Write content index
107-
ContentIndexBuilder.WriteIndex(options.OutputPath, [.. context.GeneratedPages.Select(gp => gp.Page)], continueOnError, logger);
105+
ContentIndexBuilder.WriteIndex(options.OutputPath, [.. context.GeneratedPages.Select(gp => gp.Page)], options.ContinueOnError, logger);
108106
logger.LogDebug("✅ Generated content index in {OptionsOutputPath}", options.OutputPath);
109107
}
110108

@@ -286,7 +284,6 @@ private static async Task<BlakeContext> GetBlakeContext(GenerationOptions option
286284
private static async Task BakeContent(
287285
BlakeContext context,
288286
GenerationOptions options,
289-
bool continueOnError,
290287
ILogger logger,
291288
CancellationToken cancellationToken)
292289
{
@@ -353,7 +350,7 @@ private static async Task BakeContent(
353350
catch (Exception e)
354351
{
355352
logger.LogError(e, "❌ Error processing markdown file: {MdPath}", mdPage.MdPath);
356-
if (continueOnError)
353+
if (options.ContinueOnError)
357354
{
358355
logger.LogWarning("⚠️ Continuing to process other markdown files despite the error.");
359356
}

src/Blake.CLI/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ private static async Task<int> BakeBlakeAsync(string[] args, ILogger logger, Can
206206
UseDefaultRenderers = !args.Contains("--disableDefaultRenderers") && !args.Contains("-dr"),
207207
IncludeDrafts = args.Contains("--includeDrafts"),
208208
Clean = args.Contains("--clean") || args.Contains("-cl"),
209+
ContinueOnError = args.Contains("--continueOnError") || args.Contains("-ce"),
209210
Arguments = [.. args.Skip(1)]
210211
};
211212

0 commit comments

Comments
 (0)