Skip to content

Commit

Permalink
Add debug info when can't find include
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed Jul 2, 2023
1 parent fec9e0e commit 195b589
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions MyApp/MarkdownPagesBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -383,16 +383,34 @@ protected override void Write(HtmlRenderer renderer, CustomContainerInline obj)

renderer.Write("<div").WriteAttributes(obj).Write('>');
MarkdownFileBase? doc = null;
string? slug = null;
var allIncludes = new List<MarkdownFileInfo>();
if (include.EndsWith(".md"))
{
var markdown = HostContext.Resolve<MarkdownPages>();
include = include.TrimStart('/');
var prefix = include.LeftPart('/');
var slug = include.LeftPart('.');
doc = markdown.GetVisiblePages(prefix, allDirectories: true)
.FirstOrDefault(x => x.Slug == slug);
slug = include.LeftPart('.');
allIncludes = markdown.GetVisiblePages(prefix, allDirectories: true);
doc = allIncludes.FirstOrDefault(x => x.Slug == slug);
}

if (doc?.Preview != null)
{
renderer.WriteLine(doc.Preview!);
}
else
{
var log = HostContext.Resolve<ILogger<IncludeContainerInlineRenderer>>();
log.LogError("Could not find: {Include}", include);
renderer.WriteLine($"Could not find: {include}");
renderer.WriteLine($"<!-- slug: {slug}, includes:");
foreach (var includeDoc in allIncludes)
{
renderer.WriteLine($"{includeDoc.Path}: {includeDoc.Slug}");
}
renderer.WriteLine("-->");
}
renderer.WriteLine(doc != null ? doc.Preview! : $"Could not find: {include}");
renderer.Write("</div>");
}
}
Expand Down

0 comments on commit 195b589

Please sign in to comment.