Forge
csharp3407750f
1using AgentForge.Services;
2
3namespace AgentForge.Plugin.View.Components.Docs;
4
5internal static class ForgeViewDocsIndex
6{
7 internal static string Render(
8 string repoName,
9 string branch,
10 IReadOnlyList<GitRepoService.GitTreeItem> entries)
11 {
12 var items = entries.Count == 0
13 ? [ForgeHtml.Li("meta", ForgeHtml.Fragment(
14 ForgeHtml.Text("No files in "),
15 ForgeHtml.Code("docs/"),
16 ForgeHtml.Text(".")))]
17 : entries.Select(entry => ForgeHtml.Li(null, RenderEntry(repoName, entry))).ToArray();
18
19 return ForgeHtml.Fragment(
20 ForgeHtml.H1("Documentation"),
21 ForgeHtml.P("meta",
22 ForgeHtml.Text("Read-only view of "),
23 ForgeHtml.Code("docs/"),
24 ForgeHtml.Text(" on "),
25 ForgeHtml.Code(branch),
26 ForgeHtml.Text(". Edit via git/MCP.")),
27 ForgeHtml.Ul("plain file-tree", items));
28 }
29
30 private static string RenderEntry(string repoName, GitRepoService.GitTreeItem entry)
31 {
32 var href = ForgeViewLinks.DocsHref(repoName, entry.Path);
33 if (entry.IsDirectory)
34 {
35 return ForgeHtml.Fragment(
36 ForgeHtml.Text("📁 "),
37 ForgeHtml.A(href, $"{entry.Name}/"));
38 }
39
40 return ForgeHtml.Fragment(
41 ForgeHtml.Text("📄 "),
42 ForgeHtml.A(href, entry.Name));
43 }
44}
45
46internal static class ForgeViewDocFile
47{
48 internal static string Render(
49 string repoName,
50 string branch,
51 string docsRepoPath,
52 string content)
53 {
54 var docsRelative = ForgeGitViewHelpers.ToDocsRelativePath(docsRepoPath);
55 var crumb = ForgeHtml.P("meta",
56 ForgeHtml.A(ForgeViewLinks.DocsHref(repoName), "docs/"),
57 ForgeHtml.Text(" / "),
58 ForgeHtml.Text(docsRelative),
59 ForgeHtml.Text(" · branch "),
60 ForgeHtml.Code(branch));
61
62 if (docsRepoPath.EndsWith(".md", StringComparison.OrdinalIgnoreCase))
63 {
64 var context = new ForgeViewMarkdownContext(repoName, docsRelative);
65 return ForgeHtml.Fragment(
66 crumb,
67 ForgeHtml.Article("doc-article", ForgeViewMarkdown.Render(content, context)));
68 }
69
70 return ForgeHtml.Fragment(
71 crumb,
72 ForgeHtml.Pre("doc-raw", content));
73 }
74}
75
View only · write via MCP/CIDE