Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Blake.BuildTools/Generator/ContentIndexBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ public static void WriteIndex(string outputPath, List<PageModel> allPages, bool
sb.AppendLine(" public static partial List<PageModel> GetPages() => new()");
sb.AppendLine(" {");

foreach (var page in allPages)
// Filter out draft pages - they should be accessible by URL but not listed in navigation
var nonDraftPages = allPages.Where(p => !p.Draft).ToList();

foreach (var page in nonDraftPages)
{
try
{
Expand All @@ -29,6 +32,8 @@ public static void WriteIndex(string outputPath, List<PageModel> allPages, bool
if (page.Date.HasValue)
sb.AppendLine(
$" Date = new DateTime({page.Date.Value.Year}, {page.Date.Value.Month}, {page.Date.Value.Day}),");
// Draft property is always false here since drafts are filtered out above
// We include it for consistency with PageModel structure and explicit state indication
sb.AppendLine($" Draft = {page.Draft.ToString().ToLowerInvariant()},");
Copy link

Copilot AI Dec 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Since drafts are filtered out on line 20, page.Draft will always be false here. Consider replacing page.Draft.ToString().ToLowerInvariant() with a hardcoded false on line 37 to make the code more explicit and avoid unnecessary property evaluation:

sb.AppendLine($"            Draft = false,");

This would make the code match the comment's explanation more directly.

Suggested change
sb.AppendLine($" Draft = {page.Draft.ToString().ToLowerInvariant()},");
sb.AppendLine(" Draft = false,");

Copilot uses AI. Check for mistakes.
sb.AppendLine($" IconIdentifier = @\"{page.IconIdentifier}\",");
if (page.Tags.Count > 0)
Expand Down
49 changes: 49 additions & 0 deletions tests/Blake.IntegrationTests/Commands/BlakeBakeCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,55 @@ public async Task BlakeBake_WithIncludeDraftsFlag_IncludesDrafts()
FileSystemHelper.AssertFileExists(Path.Combine(testDir, ".generated", "posts", "DraftPost.razor"));
}

[Fact]
public async Task BlakeBake_WithIncludeDraftsFlag_ExcludesDraftsFromContentIndex()
{
// Arrange
var testDir = CreateTempDirectory("blake-bake-drafts-not-in-index");

// Create a published post
FileSystemHelper.CreateMarkdownFile(
Path.Combine(testDir, "Posts", "published-post.md"),
"Published Post",
"This post is published.",
new Dictionary<string, object> { ["draft"] = false }
);

// Create a draft post
FileSystemHelper.CreateMarkdownFile(
Path.Combine(testDir, "Posts", "draft-post.md"),
"Draft Post",
"This post is a draft.",
new Dictionary<string, object> { ["draft"] = true }
);

FileSystemHelper.CreateRazorTemplate(
Path.Combine(testDir, "Posts", "template.razor"),
@"@page ""/posts/{Slug}""
<h1>@Title</h1>
<div>@Body</div>"
);

// Act
var result = await RunBlakeCommandAsync(["bake", testDir, "--includeDrafts"]);

// Assert
Assert.Equal(0, result.ExitCode);

// Both posts should be generated as razor files
FileSystemHelper.AssertFileExists(Path.Combine(testDir, ".generated", "posts", "PublishedPost.razor"));
FileSystemHelper.AssertFileExists(Path.Combine(testDir, ".generated", "posts", "DraftPost.razor"));

// Content index should be created
var indexPath = Path.Combine(testDir, ".generated", "GeneratedContentIndex.cs");
FileSystemHelper.AssertFileExists(indexPath);

// Content index should contain published post but not draft post
var indexContent = File.ReadAllText(indexPath);
Assert.Contains("Published Post", indexContent);
Assert.DoesNotContain("Draft Post", indexContent);
}

[Fact]
public async Task BlakeBake_WithTemplateInSameFolder_UsesTemplate()
{
Expand Down
Loading