Skip to content

Commit

Permalink
Add include pages info
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed Jul 2, 2023
1 parent 195b589 commit d67922a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion MyApp/Markdown.Pages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class MarkdownPages : MarkdownPagesBase<MarkdownFileInfo>
"<svg class='h-6 w-6 shrink-0 text-sky-500' fill='none' viewBox='0 0 24 24' stroke-width='1.5' stroke='currentColor' aria-hidden='true'><path stroke-linecap='round' stroke-linejoin='round' d='M2.25 12l8.954-8.955c.44-.439 1.152-.439 1.591 0L21.75 12M4.5 9.75v10.125c0 .621.504 1.125 1.125 1.125H9.75v-4.875c0-.621.504-1.125 1.125-1.125h2.25c.621 0 1.125.504 1.125 1.125V21h4.125c.621 0 1.125-.504 1.125-1.125V9.75M8.25 21h8.25'></path></svg>";

public MarkdownPages(ILogger<MarkdownPages> log, IWebHostEnvironment env) : base(log,env) {}
List<MarkdownFileInfo> Pages { get; set; } = new();
public List<MarkdownFileInfo> Pages { get; set; } = new();
public List<MarkdownFileInfo> GetVisiblePages(string? prefix=null, bool allDirectories=false) => prefix == null
? Pages.Where(x => IsVisible(x) && !x.Slug!.Contains('/')).OrderBy(x => x.Order).ThenBy(x => x.Path).ToList()
: Pages.Where(x => IsVisible(x) && x.Slug!.StartsWith(prefix.WithTrailingSlash()))
Expand Down
19 changes: 11 additions & 8 deletions MyApp/MarkdownPagesBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -384,12 +384,13 @@ protected override void Write(HtmlRenderer renderer, CustomContainerInline obj)
renderer.Write("<div").WriteAttributes(obj).Write('>');
MarkdownFileBase? doc = null;
string? slug = null;
string? prefix = null;
var allIncludes = new List<MarkdownFileInfo>();
var markdown = HostContext.Resolve<MarkdownPages>();
if (include.EndsWith(".md"))
{
var markdown = HostContext.Resolve<MarkdownPages>();
include = include.TrimStart('/');
var prefix = include.LeftPart('/');
prefix = include.LeftPart('/');
slug = include.LeftPart('.');
allIncludes = markdown.GetVisiblePages(prefix, allDirectories: true);
doc = allIncludes.FirstOrDefault(x => x.Slug == slug);
Expand All @@ -404,13 +405,15 @@ protected override void Write(HtmlRenderer renderer, CustomContainerInline obj)
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($"<!-- prefix: {prefix}, slug: {slug}, pages: {markdown.Pages.Count}, includes:");
foreach (var includeDoc in allIncludes)
{
renderer.WriteLine($"{includeDoc.Path}: {includeDoc.Slug}");
}
renderer.WriteLine("-->");

renderer.Write("</div>");
}
}
Expand Down

0 comments on commit d67922a

Please sign in to comment.