Skip to content

Self-host sample source code pages#16

Merged
TimPurdum merged 1 commit into
mainfrom
self-host-source-code-pages
Apr 30, 2026
Merged

Self-host sample source code pages#16
TimPurdum merged 1 commit into
mainfrom
self-host-source-code-pages

Conversation

@TimPurdum
Copy link
Copy Markdown
Contributor

Summary

  • Source Code pages in the sample hosts now read .razor / .razor.cs from embedded resources in Core.Sample.Shared and Pro.Sample.Shared instead of fetching .razor.txt from docs.geoblazor.com at runtime.
  • Core hosts (Wasm, WebApp Server+Client, Maui) gain the Source Code button — previously Pro-only.
  • The DocsUrl plumbing (build script flag, JSON emission, dev appsettings override) is retired.

Why

The runtime fetch coupled the samples to an external host that has to be online, CORS-friendly, and kept in lockstep with whatever ships in this repo. It also broke offline scenarios — most notably the MAUI hosts. Embedding the source in the assembly that compiles it eliminates the network hop and the drift risk.

Implementation notes

  • Pages\**\*.razor[.cs] are added as EmbeddedResource items in both Shared .csproj files with stable SampleSource/{File} LogicalNames. Razor SDK still compiles .razor files normally — EmbeddedResource is additive.
  • New ISampleSourceProvider (Shared/SampleSourceProvider.cs in Core.Sample.Shared) reads from pageType.Assembly.GetManifestResourceStream(...), so a Pro app rendering a Core page resolves source from Core, not Pro.
  • SourceNav + SourceCode moved into Core.Sample.Shared; Pro inherits via existing ProjectReference. MainLayout.AdditionalLinksType now defaults to typeof(SourceNav) so Core hosts pick it up automatically; Pro's existing override is unchanged.
  • SourceCode.razor.cs resolves the page Type by scanning loaded *Sample.Shared assemblies for routable components by name (lazy-cached). Preserves the existing /source-code/{Name} URL contract, the @code-block split, and the ## Filename headings.

Test plan

  • dotnet build Core WebApp host — passes (verified locally)
  • dotnet build Pro WebApp host — passes (verified locally)
  • dotnet build Core Wasm host — passes (verified locally)
  • dotnet build Pro Wasm host — passes (verified locally)
  • Run Pro WebApp, click Source Code on a sample, verify content loads with no request to docs.geoblazor.com in DevTools Network
  • Run Core WebApp, click Source Code on a sample (newly available)
  • Pick a page with a .razor.cs code-behind (e.g. CustomPopupContents, StyledGeoJSONLayers, UniqueValueRenderers) and verify both ## Foo.razor and ## Foo.razor.cs sections render
  • In the Pro WebApp, navigate to a Core sample and confirm the source resolves from the Core assembly
  • Build with /p:UseProjectReferences=true to confirm RazorCopy.dll and the new embedded resources coexist
  • Run a MAUI host offline and confirm Source Code still loads

Embed Pages\**\*.razor[.cs] in Core.Sample.Shared and Pro.Sample.Shared
as managed resources, and resolve them via a new ISampleSourceProvider
keyed on the page Type's assembly. The /source-code/{name} page now
loads from the local assembly instead of fetching .razor.txt from
docs.geoblazor.com.

- Move SourceNav and SourceCode from Pro.Sample.Shared to
  Core.Sample.Shared so both Core and Pro hosts get the feature
- Default Core MainLayout.AdditionalLinksType to typeof(SourceNav)
- Register ISampleSourceProvider in all 8 hosts (Core/Pro x
  Wasm/WebApp Server/WebApp Client/Maui)
- Retire DocsUrl plumbing: drop the -d/--docs-url flag and JSON
  emission from BuildAppSettings.cs, and remove the dev override
  from Pro WebApp appsettings.Development.json

Self-hosting eliminates the runtime dependency on the docs site and
makes Source Code work offline (relevant for the MAUI hosts).
@TimPurdum TimPurdum merged commit 413061e into main Apr 30, 2026
2 checks passed
@TimPurdum TimPurdum deleted the self-host-source-code-pages branch April 30, 2026 22:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant