Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScaffoldTemplates.cs
More file actions
Latest commit
271 lines (222 loc) · 10.6 KB
/
Copy pathScaffoldTemplates.cs
File metadata and controls
271 lines (222 loc) · 10.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
namespaceShellDocs.Templates;
/* Templates emitted by `shelldocs init`. Raw string constants so the CLI has
zero I/O overhead — the templates ARE the payload. */
publicstaticclassScaffoldTemplates
{
publicstaticstringIntroductionMd=>"""
---
title: Introduction
description: Get started with your ShellDocs site.
order: 1
---
# Introduction
Welcome to your new ShellDocs site. Author markdown in `content/docs/`, drop Blazor components mid-page, ship.
## What's next
- Edit this file at `content/docs/introduction.md`
- Add pages by creating more `.md` files in the same folder
- Order them via `content/docs/meta.json`
- Register components you want available inline via `RegisterComponent<T>()` in `Program.cs`
## Live components
```razor:preview
<Callout Variant="info" Title="Live component">
This block is a live Blazor component rendered from markdown.
</Callout>
```
""";
publicstaticstringMetaJson=>"""
{
"title": "Docs",
"pages": ["introduction"]
}
""";
publicstaticstringDocsPageRazor=>"""
@page "/docs/{*Path:nonfile}"
@layout DocsLayout
@using ShellDocs.Components
@using ShellDocs.Components.Content
@using ShellDocs.Components.Layouts
@using ShellDocs.Core
@using ShellDocs.Markdown
@inject NavigationGraph Graph
@inject MarkdownRenderer Renderer
<PageTitle>@_title</PageTitle>
@if (_document is not null)
{
<MarkdownContent Document="_document" />
}
else
{
<div class="doc-not-found">
<h1>Page not found</h1>
<p>The page <code>@Path</code> doesn't exist yet.</p>
<p><a href="/docs/introduction"><svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="vertical-align:middle;margin-right:0.35rem"><path d="M19 12H5M12 19l-7-7 7-7"/></svg>Back to introduction</a></p>
</div>
}
@code {
[Parameter] public string? Path { get; set; }
private RenderedDocument? _document;
private string _title = "";
protected override void OnParametersSet()
{
var url = "/docs" + (string.IsNullOrEmpty(Path) ? "" : "/" + Path);
var node = Graph.ResolveByUrl(url);
if (node?.Path is not null && System.IO.File.Exists(node.Path))
{
_document = Renderer.RenderFile(node.Path);
_title = node.Title + " — Docs";
}
else
{
_document = null;
_title = "Not found";
}
}
}
""";
/* Home.razor emitted by create mode after stripping the fresh Blazor
template's Counter/Weather demo pages. Fumadocs-style welcome — one
CTA to the docs, plus edit-this-file hints. */
publicstaticstringWelcomeHomeRazor=>"""
@page "/"
@layout HomeLayout
@using ShellDocs.Components
@using ShellDocs.Components.Chrome
@using ShellDocs.Components.Layouts
@inject ShellDocsOptions Options
<PageTitle>Home — @SiteName</PageTitle>
<div class="welcome">
<div class="welcome-hero">
<h1>Welcome to your <span class="grad">ShellDocs</span> site.</h1>
<p>Everything is wired up. Author markdown in <code>content/docs/</code>, and it renders live under <code>/docs</code>.</p>
<a href="/docs/introduction" class="btn primary">
<span>View your docs</span>
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M5 12h14M12 5l7 7-7 7"/></svg>
</a>
</div>
<div class="welcome-hints">
<div class="welcome-card">
<h2>Customize this page</h2>
<p>This welcome screen lives at <code>Components/Pages/Home.razor</code>. Edit it to build your marketing page.</p>
</div>
<div class="welcome-card">
<h2>Add pages</h2>
<p>Drop new <code>.md</code> files in <code>content/docs/</code>. Order them via <code>content/docs/meta.json</code>.</p>
</div>
<div class="welcome-card">
<h2>Register components</h2>
<p>Add <code>o.RegisterComponent<T>()</code> calls in <code>Program.cs</code> so Blazor components render in <code>razor:preview</code> blocks.</p>
</div>
</div>
</div>
<DocsFooter Version="0.1.0-alpha" />
<style>
.welcome { max-width: 44rem; margin: 4rem auto; padding: 2rem 1.5rem; }
.welcome-hero { text-align: center; margin-bottom: 3.5rem; }
.welcome-hero h1 { font-size: 2.25rem; font-weight: 700; letter-spacing: -0.025em; margin: 0 0 1rem; line-height: 1.15; }
.welcome-hero .grad {
background: linear-gradient(135deg, var(--foreground), color-mix(in oklch, var(--foreground) 60%, transparent));
-webkit-background-clip: text; background-clip: text; color: transparent;
}
.welcome-hero p { color: var(--muted-foreground); font-size: 1rem; line-height: 1.6; margin: 0 0 1.75rem; }
.welcome-hints { display: grid; grid-template-columns: 1fr; gap: 0.85rem; }
@@media (min-width: 640px) { .welcome-hints { grid-template-columns: repeat(3, 1fr); } }
.welcome-card { padding: 1rem 1.15rem; border: 1px solid var(--border); border-radius: calc(var(--radius) + 2px); background: var(--card); }
.welcome-card h2 { font-size: 0.9rem; font-weight: 600; margin: 0 0 0.4rem; letter-spacing: -0.005em; }
.welcome-card p { margin: 0; color: var(--muted-foreground); font-size: 0.85rem; line-height: 1.5; }
.welcome code { font-family: var(--font-mono); font-size: 0.85em; background: var(--muted); padding: 0.1rem 0.4rem; border-radius: 4px; border: 1px solid var(--border); }
.btn.primary {
display: inline-flex; align-items: center; gap: 0.5rem;
padding: 0.65rem 1.25rem; border-radius: 9999px;
background: var(--primary); color: var(--primary-foreground);
text-decoration: none; font-weight: 500; font-size: 0.9rem;
transition: background 150ms;
}
.btn.primary:hover { background: color-mix(in oklch, var(--primary) 90%, transparent); }
.btn.primary svg { width: 0.85rem; height: 0.85rem; }
</style>
@code {
private string SiteName => string.IsNullOrEmpty(Options.SiteName) ? "ShellDocs" : Options.SiteName;
}
""";
/* Bare pass-through MainLayout that replaces the fresh template's
sidebar+NavMenu layout. Every page uses @layout to pick its real
layout (HomeLayout or DocsLayout), so this is a fallback only. */
publicstaticstringBareMainLayoutRazor=>"""
@inherits LayoutComponentBase
@Body
""";
// --- Program.cs patch snippets ---
publicstaticstringProgramUsing=>"using ShellDocs.Components;";
publicstaticstringProgramWebHost=>"builder.WebHost.UseStaticWebAssets();";
publicstaticstringProgramAddShellDocs(stringsiteName,stringgithubRepo)=>$$"""
builder.Services.AddShellDocs(o =>
{
o.ContentRoot = System.IO.Path.Combine(builder.Environment.ContentRootPath, "content");
o.SiteName = "{{siteName}}";
o.GitHubRepo = "{{githubRepo}}";
o.AddNavLink("Docs", "/docs/introduction");
// o.RegisterComponent<MyComponent>(); // for razor:preview blocks
});
""";
// --- App.razor patch snippets ---
publicstaticstringAppTokenLinks=>"""
<link rel="stylesheet" href="_content/ShellDocs.Tokens/tokens.css" />
<link rel="stylesheet" href="_content/ShellDocs.Components/shelldocs-theme.css" />
""";
publicstaticstringAppThemeBootstrap=>"""
<script>
(function () {
var saved = null;
try { saved = localStorage.getItem('shelldocs-theme'); } catch (e) {}
var systemDark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
if ((saved || (systemDark ? 'dark' : 'light')) === 'dark') {
document.documentElement.classList.add('dark');
}
})();
</script>
""";
publicstaticstringAppScripts=>"""
<script src="_content/ShellDocs.Components/shelldocs.js"></script>
<script type="module">
import { createHighlighter } from 'https://esm.sh/shiki@1.24.0';
window.__shiki = await createHighlighter({
themes: ['github-light', 'github-dark'],
langs: ['razor', 'csharp', 'html', 'json', 'yaml', 'bash', 'typescript', 'javascript', 'markdown']
});
if (window.shelldocsHighlight) window.shelldocsHighlight();
</script>
""";
// --- Fallback: SHELLDOCS_SETUP.md for --attach mode where we can't safely patch ---
publicstaticstringSetupInstructionsMd(stringsiteName,stringgithubRepo)=>$$"""
# ShellDocs setup
Two files in your Blazor project need small additions. Copy these snippets in, then delete this file.
## 1. `Program.cs`
Add near the top with your other usings:
```csharp
{{ProgramUsing}}
```
Register the framework before `var app = builder.Build();`:
```csharp
{{ProgramWebHost}}
{{ProgramAddShellDocs(siteName,githubRepo)}}
```
## 2. `Components/App.razor`
Add these two `<link>` tags inside `<head>`, before your app styles:
```html
{{AppTokenLinks}}
```
Add this small script inside `<head>` (before `<HeadOutlet>`) — bootstraps dark mode before Blazor hydrates:
```html
{{AppThemeBootstrap}}
```
Add these before `</body>` (below `blazor.web.js` is fine):
```html
{{AppScripts}}
```
## 3. Run it
```bash
dotnet run
```
Visit `/docs/introduction`. Delete this file when done.
""";
}