|
| 1 | +@page "/console" |
| 2 | +@using Spectre.Console |
| 3 | +@inject IMarkdownContentService<SpectreConsoleFrontMatter> ConsoleContentServices |
| 4 | +@inject ContentEngineOptions ContentEngineOptions |
| 5 | + |
| 6 | +<PageTitle>Spectre.Console Documentation - @ContentEngineOptions.SiteTitle</PageTitle> |
| 7 | + |
| 8 | +<article class="prose dark:prose-invert max-w-none"> |
| 9 | + <h1>Spectre.Console Documentation</h1> |
| 10 | + <p class="lead text-lg text-base-600 dark:text-base-400"> |
| 11 | + Create beautiful, cross-platform console applications with Spectre.Console. |
| 12 | + </p> |
| 13 | + |
| 14 | + <h2>Start Here</h2> |
| 15 | + <p>Get Spectre.Console running in seconds:</p> |
| 16 | + <CodeBlock Language="bash">dotnet add package Spectre.Console</CodeBlock> |
| 17 | + |
| 18 | + <p>Then try this quick example that demonstrates styled text, a table, and a status spinner:</p> |
| 19 | + <CodeBlock Language="csharp:xmldocid,bodyonly">M:Spectre.Docs.Examples.Showcase.QuickStartSample.Run(Spectre.Console.IAnsiConsole)</CodeBlock> |
| 20 | + |
| 21 | + <p>You're application should look something like this:</p> |
| 22 | + |
| 23 | + <Screenshot Src="/assets/quickstart.svg" Alt="Screencast of Spectre.Console in action"></Screenshot> |
| 24 | + |
| 25 | + <hr /> |
| 26 | + |
| 27 | + <h2>Explore the Documentation</h2> |
| 28 | + <p> |
| 29 | + Whether you're just getting started or looking to master advanced features, we've organized everything |
| 30 | + to help you find what you need. Start with the tutorials to build a solid foundation, then dive into |
| 31 | + specific topics as your projects grow. |
| 32 | + </p> |
| 33 | + |
| 34 | + @foreach (var group in _groupedPages.OrderBy(g => GetSectionOrder(g.Key))) |
| 35 | + { |
| 36 | + <div class="mb-8"> |
| 37 | + <h2>@group.Key</h2> |
| 38 | + <ul> |
| 39 | + @foreach (var page in group.Value.OrderBy(p => p.FrontMatter.Order).ThenBy(p => p.FrontMatter.Title)) |
| 40 | + { |
| 41 | + <li> |
| 42 | + <a href="@(page.Url)">@(page.FrontMatter.Title)</a> |
| 43 | + @if (!string.IsNullOrWhiteSpace(page.FrontMatter.Description)) |
| 44 | + { |
| 45 | + <span class="text-base-500 dark:text-base-400"> - @(page.FrontMatter.Description)</span> |
| 46 | + } |
| 47 | + </li> |
| 48 | + } |
| 49 | + </ul> |
| 50 | + </div> |
| 51 | + } |
| 52 | +</article> |
| 53 | + |
| 54 | +@code { |
| 55 | + private Dictionary<string, List<MarkdownContentPage<SpectreConsoleFrontMatter>>> _groupedPages = new(); |
| 56 | + |
| 57 | + private static readonly Dictionary<string, string> SectionNames = new() |
| 58 | + { |
| 59 | + { "tutorials", "Tutorials" }, |
| 60 | + { "how--to", "How-To Guides" }, |
| 61 | + { "widgets", "Widgets" }, |
| 62 | + { "live", "Live Rendering" }, |
| 63 | + { "prompts", "Prompts" }, |
| 64 | + { "reference", "Reference" }, |
| 65 | + { "explanation", "Explanation" } |
| 66 | + }; |
| 67 | + |
| 68 | + private static readonly Dictionary<string, int> SectionOrder = new() |
| 69 | + { |
| 70 | + { "Tutorials", 1 }, |
| 71 | + { "How-To Guides", 2 }, |
| 72 | + { "Widgets", 3 }, |
| 73 | + { "Prompts", 4 }, |
| 74 | + { "Live Rendering", 5 }, |
| 75 | + { "Explanation", 6 }, |
| 76 | + { "Reference", 7 }, |
| 77 | + }; |
| 78 | + |
| 79 | + private static int GetSectionOrder(string sectionName) => |
| 80 | + SectionOrder.GetValueOrDefault(sectionName, 99); |
| 81 | + |
| 82 | + protected override async Task OnInitializedAsync() |
| 83 | + { |
| 84 | + var allPages = await ConsoleContentServices.GetAllContentPagesAsync(); |
| 85 | + |
| 86 | + // Group pages by their first path segment after /console/ |
| 87 | + foreach (var page in allPages) |
| 88 | + { |
| 89 | + var pathParts = page.Url.Split('/', StringSplitOptions.RemoveEmptyEntries); |
| 90 | + if (pathParts.Length >= 2) |
| 91 | + { |
| 92 | + var sectionKey = pathParts[1]; // e.g., "tutorials", "how--to", "widgets" |
| 93 | + var sectionName = SectionNames.GetValueOrDefault(sectionKey, sectionKey); |
| 94 | + |
| 95 | + if (!_groupedPages.ContainsKey(sectionName)) |
| 96 | + { |
| 97 | + _groupedPages[sectionName] = []; |
| 98 | + } |
| 99 | + _groupedPages[sectionName].Add(page); |
| 100 | + } |
| 101 | + } |
| 102 | + |
| 103 | + await base.OnInitializedAsync(); |
| 104 | + } |
| 105 | +} |
0 commit comments