Skip to content

Commit ba94b27

Browse files
committed
feat: enhance ShellDocs configuration with ShellDocsOptions class and improved service registration for navigation and Markdown rendering
1 parent 0e26f87 commit ba94b27

3 files changed

Lines changed: 71 additions & 23 deletions

File tree

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,31 @@
11
using Microsoft.Extensions.DependencyInjection;
2+
using ShellDocs.Components.Chrome;
23
using ShellDocs.Core;
4+
using ShellDocs.Markdown;
35

46
namespace ShellDocs.Components;
57

6-
/// Registers ShellDocs services with the consumer's DI container.
7-
/// Consumer's Program.cs calls this once — everything else is discovered by convention.
88
public static class ServiceCollectionExtensions
99
{
10-
public static IServiceCollection AddShellDocs(
11-
this IServiceCollection services,
12-
Action<ShellDocsOptions>? configure = null)
10+
public static IServiceCollection AddShellDocs(this IServiceCollection services, Action<ShellDocsOptions>? configure = null)
1311
{
1412
var options = new ShellDocsOptions();
1513
configure?.Invoke(options);
1614
services.AddSingleton(options);
1715

18-
// Real service wiring lands in feat/core-navigation-graph + feat/markdown-pipeline.
19-
// Scaffolding: keep the surface consumers will call, no implementation yet.
20-
return services;
21-
}
22-
}
16+
services.AddScoped<MobileNavState>();
17+
services.AddSingleton<TypeRegistry>(_ => options.BuildTypeRegistry());
18+
services.AddSingleton<MarkdownRenderer>(sp => new MarkdownRenderer(sp.GetRequiredService<TypeRegistry>()));
2319

24-
/// Fluent options bag consumers configure in Program.cs.
25-
public class ShellDocsOptions
26-
{
27-
public string ContentRoot { get; set; } = "content";
28-
public string SiteName { get; set; } = "";
29-
public string? GitHubRepo { get; set; }
30-
public bool EnableSearch { get; set; } = true;
31-
public string SearchIndexPath { get; set; } = "search-index.json";
32-
public List<Type> RegisteredComponents { get; } = new();
20+
services.AddSingleton<NavigationGraph>(_ =>
21+
{
22+
if (!Directory.Exists(options.ContentRoot))
23+
{
24+
return new NavigationGraph(new NavigationNode { Url = "/", Kind = NodeKind.Section });
25+
}
26+
return NavigationGraphBuilder.Build(options.ContentRoot);
27+
});
3328

34-
public ShellDocsOptions RegisterComponent<T>() where T : Microsoft.AspNetCore.Components.ComponentBase
35-
{
36-
RegisteredComponents.Add(typeof(T));
37-
return this;
29+
return services;
3830
}
3931
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using ShellDocs.Markdown;
2+
3+
namespace ShellDocs.Components;
4+
5+
public class ShellDocsOptions
6+
{
7+
public string ContentRoot { get; set; } = "content";
8+
public string SiteName { get; set; } = "";
9+
public string? SiteTagline { get; set; }
10+
public string? GitHubRepo { get; set; }
11+
public ShellDocsTheme Theme { get; set; } = ShellDocsTheme.Shadcn;
12+
13+
public List<NavLink> PrimaryNav { get; } = new();
14+
public List<Type> RegisteredComponents { get; } = new();
15+
16+
public ShellDocsOptions RegisterComponent<T>() where T : Microsoft.AspNetCore.Components.ComponentBase
17+
{
18+
RegisteredComponents.Add(typeof(T));
19+
return this;
20+
}
21+
22+
public ShellDocsOptions AddNavLink(string label, string href)
23+
{
24+
PrimaryNav.Add(new NavLink(label, href));
25+
return this;
26+
}
27+
28+
public ShellDocsOptions AddNavMenu(string label, params NavMenuItem[] items)
29+
{
30+
PrimaryNav.Add(new NavLink(label, "#", Children: items.ToList()));
31+
return this;
32+
}
33+
34+
internal TypeRegistry BuildTypeRegistry()
35+
{
36+
var registry = new TypeRegistry();
37+
foreach (var type in RegisteredComponents) registry.Register(type);
38+
return registry;
39+
}
40+
}
41+
42+
public record NavLink(string Label, string Href, List<NavMenuItem>? Children = null);
43+
public record NavMenuItem(string Label, string Href, string? Description = null, string? IconSvg = null);
44+
45+
public enum ShellDocsTheme
46+
{
47+
Shadcn,
48+
Fuma,
49+
Nextra
50+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
@using System.Net.Http
22
@using System.Net.Http.Json
33
@using Microsoft.AspNetCore.Components
4+
@using Microsoft.AspNetCore.Components.CompilerServices
45
@using Microsoft.AspNetCore.Components.Forms
56
@using Microsoft.AspNetCore.Components.Routing
67
@using Microsoft.AspNetCore.Components.Web
8+
@using Microsoft.Extensions.DependencyInjection
79
@using Microsoft.JSInterop
810
@using ShellDocs.Components
11+
@using ShellDocs.Components.Chrome
12+
@using ShellDocs.Components.Content
13+
@using ShellDocs.Components.Layouts
914
@using ShellDocs.Core
15+
@using ShellDocs.Markdown

0 commit comments

Comments
 (0)