Skip to content

Commit 21fdb18

Browse files
committed
docs: update content for ShellDocs 0.1.13 through 0.1.15
Search works on a static export; code tabs on previews, IframePreview, the not-found page and the sidebar collapse are documented. New pages: components/code-tabs, components/iframe-preview, guides/search, guides/not-found.
1 parent 781080b commit 21fdb18

25 files changed

Lines changed: 599 additions & 40 deletions

‎README.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,12 @@ content/
5858
configuration.md
5959
authoring/ frontmatter, code fences, razor:preview, inline tags, navigation
6060
components/ one page per content primitive
61-
guides/ component libraries, versioning, redirects, deployment
61+
guides/ component libraries, versioning, redirects, search, not-found, deployment
6262
cli/ init, add, dev, build
6363
theming.md
6464
packages/ one overview per NuGet package
65+
wwwroot/
66+
demos/ static pages shown with <IframePreview>
6567
Components/
6668
Demos/ demo components shown with <DemoPreview>
6769
```

‎content/docs/authoring/fenced-code.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ dotnet add package ShellDocs.Components --prerelease
109109
<CodeTab Label="PackageReference">
110110

111111
```xml
112-
<PackageReference Include="ShellDocs.Components" Version="0.1.12-alpha" />
112+
<PackageReference Include="ShellDocs.Components" Version="0.1.15-alpha" />
113113
```
114114

115115
</CodeTab>

‎content/docs/cli/build.md‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,28 @@ The site is written to `./publish`.
3131
Runs `dotnet publish -c Release` into a scratch folder under `obj/`.
3232
</Step>
3333
<Step Title="Makes sure the content is there">
34-
Copies any file under `content/` that publish left out. A project that copies `meta.json` but not the `.md` files would otherwise prerender every page as "Page not found".
34+
Copies any file under `content/` that publish left out. A project that copies `meta.json` but not the `.md` files would otherwise prerender every page as not found.
3535
</Step>
3636
<Step Title="Finds every URL">
3737
Reads the navigation graph from `content/`, hidden pages included, and adds the home page.
3838
</Step>
3939
<Step Title="Prerenders each page">
40-
Starts the published app on a local port, requests each URL, and saves the response as `index.html` in a folder named after the URL.
40+
Starts the published app on a local port, requests each URL, and saves the response as `index.html` in a folder named after the URL. A page that answers 404, or renders the not-found view, fails the build.
4141
</Step>
4242
<Step Title="Writes redirect pages">
4343
Asks the running app for its redirect map and writes a small redirect page at each source URL. See [Redirects](/docs/guides/redirects).
4444
</Step>
45+
<Step Title="Writes the not-found page">
46+
Requests a URL that doesn't exist and saves the site's not-found view as `404.html`. See [Not-found page](/docs/guides/not-found).
47+
</Step>
48+
<Step Title="Copies the search index">
49+
Saves the app's search index as `_shelldocs/search.json`, which is what makes search work without a server.
50+
</Step>
4551
<Step Title="Copies the assets">
4652
Merges the published `wwwroot` into the output: framework scripts, `shelldocs.js`, stylesheets, your own static files. Prerendered pages are never overwritten.
4753
</Step>
4854
<Step Title="Applies the optional flags">
49-
Rewrites the base href, writes `404.html`, and adds the sitemap, robots file and social meta tags when asked.
55+
Rewrites the base href, replaces `404.html` with the home page, and adds the sitemap, robots file and social meta tags when asked.
5056
</Step>
5157
</Steps>
5258

@@ -82,7 +88,9 @@ shelldocs build --base-href /my-repo/
8288

8389
### `--spa-fallback`
8490

85-
Copies the root `index.html` to `404.html`. GitHub Pages serves `404.html` for any URL that has no file.
91+
Replaces `404.html` with a copy of the root `index.html`, so a host that serves `404.html` for unknown URLs shows the home page instead of the not-found page.
92+
93+
Leave it off unless the site has pages of its own that are routed in the browser and never prerendered. Without the flag, `404.html` is the site's not-found page, which tells the reader the address is wrong and links back to the docs.
8694

8795
### `--output` and `--dir`
8896

@@ -94,21 +102,21 @@ Copies the root `index.html` to `404.html`. GitHub Pages serves `404.html` for a
94102
<TypeRow Name="--dir" Type="string" Default="current folder" Description="Project folder. Must contain a .csproj and a content folder." />
95103
<TypeRow Name="--output" Type="string" Default="publish" Description="Output folder for the static site." />
96104
<TypeRow Name="--base-href" Type="string?" Default="—" Description="Base path for a site served from a subpath, with leading and trailing slashes." />
97-
<TypeRow Name="--spa-fallback" Type="bool" Default="false" Description="Also write the home page as 404.html." />
105+
<TypeRow Name="--spa-fallback" Type="bool" Default="false" Description="Write the home page as 404.html, in place of the not-found page." />
98106
<TypeRow Name="--site-url" Type="string?" Default="—" Description="Absolute site address. Turns on the sitemap, robots file and social meta tags." />
99107
</TypeTable>
100108

101109
## Exit codes
102110

103111
<TypeTable>
104112
<TypeRow Name="0" Type="ok" Description="Site written." />
105-
<TypeRow Name="1" Type="error" Description="No .csproj or no content folder found, the navigation graph could not be read, or prerendering did not finish cleanly." />
113+
<TypeRow Name="1" Type="error" Description="No .csproj or no content folder found, the navigation graph could not be read, a page rendered as not found, or prerendering did not finish cleanly." />
106114
<TypeRow Name="other" Type="pass-through" Description="The exit code of dotnet publish when it fails." />
107115
</TypeTable>
108116

109117
## What a static site can't do
110118

111-
Search and anything driven by Blazor event handlers need a running app. The full list is in [Deployment](/docs/guides/deployment).
119+
Search, the sidebar, tabs and the rest of the chrome work in the export: `shelldocs.js` drives them. Only what depends on Blazor event handlers needs a running app, such as a live demo with `@onclick` handlers. The full list is in [Deployment](/docs/guides/deployment).
112120

113121
## See also
114122

‎content/docs/cli/init.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Inserts a `<Content Update="content/**/*.md;content/**/meta.json" CopyToOutputDi
3838
Creates `content/docs/introduction.md` and `content/docs/meta.json` : the minimum a ShellDocs site needs to render.
3939
</Step>
4040
<Step Title="Writes `Components/Pages/DocsPage.razor`">
41-
The single-page router that serves every `/docs/**` URL from the `.md` files under `content/`. You don't edit this : it's just a `<DocsLayout>` around a `<MarkdownContent>`.
41+
The single-page router that serves every `/docs/**` URL from the `.md` files under `content/`. You don't edit this : it's just a `<DocsLayout>` around a `<MarkdownContent>`, with `<DocsNotFound />` for a URL that has no page.
4242
</Step>
4343
<Step Title="Strips the fresh-template chrome">
4444
Deletes `Counter.razor`, `Weather.razor`, `NavMenu.razor`, `MainLayout.razor.css`, `Home.razor.css`. Rewrites `MainLayout.razor` as a bare pass-through and replaces `Home.razor` with the ShellDocs welcome page.

‎content/docs/components/code-group.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ dotnet add package ShellDocs.Components --prerelease
2121
<CodeTab Label="PackageReference">
2222

2323
```xml
24-
<PackageReference Include="ShellDocs.Components" Version="0.1.12-alpha" />
24+
<PackageReference Include="ShellDocs.Components" Version="0.1.15-alpha" />
2525
```
2626

2727
</CodeTab>
@@ -41,7 +41,7 @@ dotnet add package ShellDocs.Components --prerelease
4141
<CodeTab Label="PackageReference">
4242

4343
```xml
44-
<PackageReference Include="ShellDocs.Components" Version="0.1.12-alpha" />
44+
<PackageReference Include="ShellDocs.Components" Version="0.1.15-alpha" />
4545
```
4646

4747
</CodeTab>
@@ -63,7 +63,7 @@ dotnet add package ShellDocs.Core --prerelease
6363
<CodeTab Label="PackageReference">
6464

6565
```xml
66-
<PackageReference Include="ShellDocs.Core" Version="0.1.12-alpha" />
66+
<PackageReference Include="ShellDocs.Core" Version="0.1.15-alpha" />
6767
```
6868

6969
</CodeTab>
@@ -80,7 +80,7 @@ dotnet add package ShellDocs.Markdown --prerelease
8080
<CodeTab Label="PackageReference">
8181

8282
```xml
83-
<PackageReference Include="ShellDocs.Markdown" Version="0.1.12-alpha" />
83+
<PackageReference Include="ShellDocs.Markdown" Version="0.1.15-alpha" />
8484
```
8585

8686
</CodeTab>
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
---
2+
title: Code tabs on previews
3+
description: Replace a preview's Code panel with tabs you write, switch them together across the site, and add a page-level switch and a caption.
4+
order: 13
5+
---
6+
7+
# Code tabs on previews
8+
9+
A preview's Code panel normally shows the Razor that rendered it. Put `<CodeTab>` children inside the preview and the panel shows those instead, one tab each. Use it when the reader's code isn't the code that drew the example : the same result in two syntaxes, or one live example documented for several platforms.
10+
11+
<SyncSwitch SyncKey="syntax" Options="Markdown, Razor" />
12+
13+
<DemoPreview Component="PackageFamilyDemo" Layout="stretch" SyncKey="syntax" Caption="Rendered with Blazor">
14+
<CodeTab Label="Markdown">
15+
16+
```markdown
17+
<CardGrid Columns="2">
18+
<Card Title="ShellDocs.Components" Description="Layouts, chrome and the content primitives." />
19+
<Card Title="ShellDocs.Markdown" Description="The Markdig pipeline and component slots." />
20+
<Card Title="ShellDocs.Core" Description="Navigation graph and search index." />
21+
<Card Title="ShellDocs.Tokens" Description="Design tokens as CSS variables." />
22+
</CardGrid>
23+
```
24+
25+
</CodeTab>
26+
<CodeTab Label="Razor">
27+
28+
```razor
29+
<CardGrid Columns="2">
30+
@foreach (var package in Packages)
31+
{
32+
<Card Title="@package.Name" Description="@package.Summary" />
33+
}
34+
</CardGrid>
35+
```
36+
37+
</CodeTab>
38+
</DemoPreview>
39+
40+
Written as:
41+
42+
````markdown
43+
<DemoPreview Component="PackageFamilyDemo" Layout="stretch" SyncKey="syntax" Caption="Rendered with Blazor">
44+
<CodeTab Label="Markdown">
45+
46+
```markdown
47+
<CardGrid Columns="2">
48+
<Card Title="ShellDocs.Components" Description="Layouts, chrome and the content primitives." />
49+
</CardGrid>
50+
```
51+
52+
</CodeTab>
53+
<CodeTab Label="Razor">
54+
55+
```razor
56+
<CardGrid Columns="2">
57+
@foreach (var package in Packages)
58+
{
59+
<Card Title="@package.Name" Description="@package.Summary" />
60+
}
61+
</CardGrid>
62+
```
63+
64+
</CodeTab>
65+
</DemoPreview>
66+
````
67+
68+
## The rules
69+
70+
- Each tab's code is the first fence inside it. The fence's language drives highlighting.
71+
- Without a fence, the tag's text is the code and `Language="…"` sets the language.
72+
- The **Copy** button copies the tab that is showing.
73+
- Without `<CodeTab>` children the Code panel shows the Razor source, as before.
74+
75+
## Where they work
76+
77+
<TypeTable>
78+
<TypeRow Name="DemoPreview" Type="yes" Description="The tabs replace the demo's .razor file in the Code panel." />
79+
<TypeRow Name="ComponentPreview" Type="yes" Description="The tabs are taken out of the body before it is passed to the component as child content." />
80+
<TypeRow Name="IframePreview" Type="yes" Description="Without tabs an iframe preview has no Code panel at all." />
81+
<TypeRow Name="razor:preview fence" Type="no" Description="The fence body is Razor, so a code fence can't sit inside it. Use DemoPreview instead." />
82+
</TypeTable>
83+
84+
## Switching together
85+
86+
`SyncKey` works as it does on [`CodeGroup`](/docs/components/code-group) and [`Tabs`](/docs/components/tabs). Every block with the same key switches together, on this page and on later ones, and the choice is saved in `localStorage`.
87+
88+
## A missing tab
89+
90+
When a block has no tab for the current choice it says so and keeps its height, instead of jumping to another tab. Choose **Razor** in the first example, then look at this one:
91+
92+
<DemoPreview Component="PackageFamilyDemo" Id="family-markdown-only" Layout="stretch" SyncKey="syntax">
93+
<CodeTab Label="Markdown">
94+
95+
```markdown
96+
<CardGrid Columns="2">
97+
<Card Title="ShellDocs.Components" Description="Layouts, chrome and the content primitives." />
98+
</CardGrid>
99+
```
100+
101+
</CodeTab>
102+
</DemoPreview>
103+
104+
## Page switch
105+
106+
A page switch is a row of tabs on the page itself that drives a `SyncKey`. The **Markdown | Razor** row at the top of this page is one. Declare it once and it appears on every page whose blocks use that key:
107+
108+
```csharp
109+
builder.Services.AddShellDocs(o =>
110+
{
111+
o.AddSyncSwitch("platform", "MAUI", "Avalonia");
112+
});
113+
```
114+
115+
It sits under the page header when `RenderPageTitle` is on, otherwise right above the first block that uses the key. Pages that don't use the key don't get one. The first option is the default until a reader picks another, so every block starts on the same tab.
116+
117+
To choose the spot yourself, write the tag. The automatic one is then left out on that page:
118+
119+
```markdown
120+
<SyncSwitch SyncKey="platform" />
121+
```
122+
123+
For a key with no `AddSyncSwitch`, list the options on the tag. This page does that:
124+
125+
```markdown
126+
<SyncSwitch SyncKey="syntax" Options="Markdown, Razor" />
127+
```
128+
129+
<TypeTable>
130+
<TypeRow Name="SyncKey" Type="string" Default="—" Required="true" Description="The key the switch drives." />
131+
<TypeRow Name="Options" Type="string?" Default="from AddSyncSwitch" Description="Comma-separated option labels. They must match the tab labels." />
132+
</TypeTable>
133+
134+
## Caption
135+
136+
`Caption` adds a short muted note to the preview's toolbar, such as which platform rendered the example. The first preview on this page has one.
137+
138+
```markdown
139+
<DemoPreview Component="PackageFamilyDemo" Caption="Rendered with Blazor" />
140+
```
141+
142+
`ShellDocsOptions.PreviewCaption` sets a caption for every preview on the site. A preview's own `Caption` replaces it.
143+
144+
```csharp
145+
o.PreviewCaption = "Rendered with Blazor";
146+
```
147+
148+
## From a Razor file
149+
150+
Outside markdown, pass the tabs as a parameter:
151+
152+
```razor
153+
<DemoPreview Component="PackageFamilyDemo"
154+
SyncKey="syntax"
155+
CodeTabs="@(new PreviewCodeTab[] { new("Markdown", markdownSource, "markdown") })" />
156+
```
157+
158+
A `PreviewCodeTab` is a label, the code, and a language that defaults to `text`.
159+
160+
## XAML
161+
162+
`xaml` and `axaml` fences are highlighted as XML. Sites created before `0.1.13-alpha` need `'xml'` in the `langs` list of the Shiki loader in `App.razor`.
163+
164+
## Props
165+
166+
These are the same on `DemoPreview`, `ComponentPreview` and `IframePreview`.
167+
168+
<TypeTable>
169+
<TypeRow Name="SyncKey" Type="string?" Default="—" Description="Blocks with the same key switch together and remember the choice." />
170+
<TypeRow Name="Caption" Type="string?" Default="PreviewCaption" Description="Muted note in the toolbar." />
171+
<TypeRow Name="CodeTabs" Type="IReadOnlyList<PreviewCodeTab>?" Default="—" Description="The tabs, when the preview is written in a .razor file." />
172+
</TypeTable>
173+
174+
`CodeTab` inside a preview:
175+
176+
<TypeTable>
177+
<TypeRow Name="Label" Type="string" Default="—" Required="true" Description="Tab label, and the value a SyncKey matches on." />
178+
<TypeRow Name="Language" Type="string?" Default="text" Description="Highlighting language when the body has no fence." />
179+
</TypeTable>
180+
181+
## See also
182+
183+
<CardGrid Columns="2">
184+
<LinkCard Title="DemoPreview" Description="The preview these tabs most often sit in." Href="/docs/components/demo-preview" />
185+
<LinkCard Title="IframePreview" Description="A live example from another page, with the same tabs." Href="/docs/components/iframe-preview" />
186+
</CardGrid>

‎content/docs/components/component-preview.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,17 @@ builder.Services.AddShellDocs(o =>
6464
});
6565
```
6666

67+
## Code tabs
68+
69+
`<CodeTab>` children replace the generated tag in the Code panel. They are taken out of the body first, so the target component never receives them as child content. `SyncKey` and `Caption` work as on `DemoPreview`. See [Code tabs on previews](/docs/components/code-tabs).
70+
6771
## Props
6872

6973
<TypeTable>
7074
<TypeRow Name="Component" Type="string" Default="—" Required="true" Description="Tag name of the component to preview." />
7175
<TypeRow Name="Layout" Type="string?" Default="center" Description="center, stretch or scroll." />
76+
<TypeRow Name="SyncKey" Type="string?" Default="—" Description="Sync key for its code tabs." />
77+
<TypeRow Name="Caption" Type="string?" Default="PreviewCaption" Description="Muted note in the toolbar." />
7278
<TypeRow Name="ChildContent" Type="RenderFragment?" Default="—" Description="Passed to the target as its child content." />
7379
<TypeRow Name="other attributes" Type="any" Default="—" Description="Forwarded to the target component." />
7480
</TypeTable>

‎content/docs/components/demo-preview.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ The Razor SDK leaves `.razor` files out of publish output. Copy them with a `Non
6666

6767
A demo with `@onclick` handlers needs a running Blazor app. On a static export the demo renders in its initial state and doesn't respond. Demos that only compute what to render, like the one above, work everywhere. See [Deployment](/docs/guides/deployment).
6868

69+
## Code for something other than the demo
70+
71+
By default the Code tab shows the demo's `.razor` file. Put `<CodeTab>` children inside the tag and it shows those instead, one tab each : the same example in another syntax, or for another platform. `SyncKey` switches them together across the site and `Caption` adds a note to the toolbar. See [Code tabs on previews](/docs/components/code-tabs).
72+
6973
## The same demo twice
7074

7175
The frame's anchor is `demo-{component}`. When a page shows one demo more than once, give each its own `Id`:
@@ -85,11 +89,16 @@ A red panel replaces the example when the component isn't registered, when `Demo
8589
<TypeRow Name="Title" Type="string?" Default="—" Description="Title in the frame header." />
8690
<TypeRow Name="Layout" Type="string?" Default="center" Description="center, stretch or scroll." />
8791
<TypeRow Name="Id" Type="string?" Default="demo-{component}" Description="Anchor id for the frame." />
92+
<TypeRow Name="SyncKey" Type="string?" Default="—" Description="Sync key for its code tabs." />
93+
<TypeRow Name="Caption" Type="string?" Default="PreviewCaption" Description="Muted note in the toolbar." />
94+
<TypeRow Name="CodeTabs" Type="IReadOnlyList<PreviewCodeTab>?" Default="—" Description="Code tabs, when the preview is written in a .razor file. In markdown, use CodeTab children." />
8895
</TypeTable>
8996

9097
## See also
9198

9299
<CardGrid Columns="2">
93100
<LinkCard Title="razor:preview" Description="For examples that are plain markup." Href="/docs/authoring/razor-preview" />
94101
<LinkCard Title="AutoTypeTable" Description="Generate the props table for the same component." Href="/docs/components/auto-type-table" />
102+
<LinkCard Title="Code tabs on previews" Description="Show code for several targets in the Code panel." Href="/docs/components/code-tabs" />
103+
<LinkCard Title="IframePreview" Description="A live example that is another page, not a Blazor component." Href="/docs/components/iframe-preview" />
95104
</CardGrid>

0 commit comments

Comments
 (0)