Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,19 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [1.1.1] - 2026-11-26

This is a patch release that adds destination-aware framework view fallback routing and branded HTTP error pages with client-side recovery, expands unit, container, Playwright, and Cuemon acceptance tests, and enforces the six-tag versioned Docker image policy without `:latest`.

### Added

- Added destination-aware framework view fallback (`framework-views/FrameworkViewConventions.ps1`, `framework-views/Build-DocfxFrameworkViews.ps1`, `framework-views/framework-views.nginx.conf`, and `templates/ms-style/public/framework-view.js`), generating an ordinal-keyed, deduplicated `availability` inventory (`sets` and `pages`) in `framework-views.json`, merging missing API section links into shared root `toc.json` by item name and normalized identity href, routing unavailable HTML pages and directory indexes via NGINX HTTP `302` fallback (stripping `view` parameters while preserving other query parameters and returning HTTP `400` for excess duplicate `view` parameters), and resolving destination-aware links in `framework-view.js` across navigation, search results, and the framework selector,
- Added branded HTTP error pages (`framework-views/DocfxHttpErrors.ps1`, `framework-views/http-error.md.tmpl`, `framework-views/http-error.js`, `framework-views/framework-views.nginx.conf`, `framework-views/Build-DocfxFrameworkViews.ps1`, and `framework-views/FrameworkViewConventions.ps1`), generating static DocFX error pages under `/_docfx-errors/` (reserving `_docfx-errors` in `Get-ApiPath`) for 19 HTTP status codes (`400`–`505`), routing HTML navigation errors to `/_docfx-errors/$status.html` and non-HTML requests to `@docfx_plain_error`, and serving isolated `public/docfx-http-error.js` recovery actions for documentation home, session-history back navigation, search, retry (including fresh `GET` navigation when URLs contain fragments), and `400`/`404` framework availability links,
- Added expanded automated verification (`tests/framework-view/http-error.spec.js`, `tests/framework-view/framework-view.spec.js`, `tests/framework-view/FrameworkViewConventions.Tests.ps1`, `tests/framework-view/Build-DocfxFrameworkViews.Tests.ps1`, `tests/Test-DocfxContainer.ps1`, `tests/framework-view/Test-FrameworkView.ps1`, `tests/framework-view/Test-FrameworkViews.ps1`, `tests/framework-view/cuemon/Build-CuemonFixture.ps1`, `tests/framework-view/cuemon/Test-CuemonFrameworkViews.ps1`, and `tests/framework-view/fixture/`) covering destination-aware fallback, identity-based TOC merging, ordinal page availability keys, and branded HTTP error pages for multi-TFM and single-TFM sites.

### Changed

- Updated repository documentation (`README.md`, `framework-views/README.md`, and `tests/framework-view/README.md`) to cover destination-aware framework view fallback, page availability metadata, shared root TOC merging, branded HTTP error pages, and the expanded browser and Cuemon acceptance tests,
- Updated repository documentation (`README.md`, `framework-views/README.md`, `AGENTS.md`) and delivery tests (`tests/BuildAndPushDocfxImage.Tests.ps1`, `tests/ReleaseDelivery.Tests.ps1`) to document and enforce the six-tag versioned Docker image policy (three floating versioned convenience tags and three Codebelt engine-qualified tags).

### Removed
Expand Down Expand Up @@ -104,7 +113,7 @@ This is the initial release of the DocFX builder Docker image.
- Added a DocFX builder Docker image that includes the default and modern templates,
- Added support for running the DocFX build process in a container.

[Unreleased]: https://github.com/codebeltnet/docfx/compare/v1.1.0..HEAD
[1.1.1]: https://github.com/codebeltnet/docfx/compare/v1.1.0..v1.1.1
[1.1.0]: https://github.com/codebeltnet/docfx/compare/v1.0.1..v1.1.0
[1.0.1]: https://github.com/codebeltnet/docfx/compare/v1.0.0..v1.0.1
[1.0.0]: https://github.com/codebeltnet/docfx/compare/v0.1.4..v1.0.0
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ This repository distributes the DocFX builder image, shared templates and native

Framework views generate one native set of API pages, xrefs and search results per evaluated project target framework. From the consumer repository root, the generator reads `.docfx/docfx.json` and writes to `.bot/docfx`. The same PowerShell entry point runs on Windows, Linux, CI and in the builder image. Ordinary DocFX sites continue to use the standard CLI. [Framework views setup and migration](framework-views/README.md)

Sites served by the generated NGINX configuration automatically get branded HTTP error pages, including sites that target a single framework. [HTTP error pages](framework-views/README.md#http-error-pages)

Consuming repositories only need to provide their DocFX metadata and content with a command such as `ADD [".", "docfx"]` in their documentation Dockerfile.

The image includes DocFX's `default` and `modern` templates and the Codebelt `ms-style` compatibility overlay. The overlay is intended for API reference sites maintained by the Codebelt ecosystem, including:
Expand Down
14 changes: 11 additions & 3 deletions framework-views/Build-DocfxFrameworkViews.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ $ErrorActionPreference = 'Stop'
$PSNativeCommandUseErrorActionPreference = $false
. "$PSScriptRoot/FrameworkViewConventions.ps1"
. "$PSScriptRoot/DocfxMetadata.ps1"
. "$PSScriptRoot/DocfxHttpErrors.ps1"

function Invoke-Step([string] $Log, [string] $Command, [string[]] $Arguments, [switch] $ReturnExitCode) {
& $Command @Arguments *> $Log
Expand Down Expand Up @@ -194,6 +195,7 @@ try {
New-Item -ItemType Directory -Path $cacheRoot -Force | Out-Null
}
$restored = [Collections.Generic.HashSet[string]]::new([StringComparer]::Ordinal)
$defaultView = @($views.Keys)[0]
foreach ($view in $views.Keys) {
$entry = $views[$view]
$tfm = $entry.tfm
Expand Down Expand Up @@ -263,6 +265,7 @@ try {
})
New-Item -ItemType Directory -Path "$stage/framework-template" | Out-Null
Copy-Item -LiteralPath $templateSource -Destination "$stage/framework-template/ms-style" -Recurse
if ($view -ceq $defaultView) { $errorStatuses = @(New-DocfxHttpErrors $stage $build $ApiPath) }
Write-Json "$stage/framework-build.json" @{ build = $build }
Invoke-Step "$stage/build.log" $docfx @('build', "$stage/framework-build.json")
Write-Host "$view rendered $count metadata UIDs"
Expand All @@ -271,7 +274,6 @@ try {
Pop-Location
}

$defaultView = @($views.Keys)[0]
$site = "$work/site"
Copy-Item -LiteralPath "$work/$($views[$defaultView].directory)/$buildDestination" -Destination $site -Recurse
$routes = foreach ($view in $views.Keys) {
Expand Down Expand Up @@ -301,9 +303,15 @@ try {
$root = if ($view -ceq $defaultView) { '""' } else { "/_frameworks/$directory" }
' ~^{0}$ {1};' -f [regex]::Escape($directory), $root
}
Write-Json "$site/framework-views.json" ([ordered]@{ schemaVersion = 1; apiPath = "/$ApiPath/"; defaultView = $defaultView; viewOrder = @($views.Keys); views = $views })
$availability = Get-FrameworkPageAvailability $site $ApiPath $defaultView $views
Merge-SharedNavigationToc $site $work $buildDestination $ApiPath $defaultView $views $availability
$fallbackRoutes = Get-FrameworkNginxFallbackRules $defaultView $views
Write-Json "$site/framework-views.json" ([ordered]@{ schemaVersion = 1; apiPath = "/$ApiPath/"; defaultView = $defaultView; viewOrder = @($views.Keys); views = $views; availability = $availability })
Complete-DocfxHttpErrors $site $errorStatuses
(Get-Content -LiteralPath "$PSScriptRoot/framework-views.nginx.conf" -Raw).Replace('__API__', "/$ApiPath/").
Replace('__VIEWS__', ($routes -join "`n")).Replace('__SEARCH__', ($searchRoutes -join "`n")) | Set-Content -LiteralPath "$work/nginx.conf"
Replace('__VIEWS__', ($routes -join "`n")).Replace('__SEARCH__', ($searchRoutes -join "`n")).
Replace('__FALLBACK__', ($fallbackRoutes -join "`n")).
Replace('__ERROR_STATUS__', ($errorStatuses -join ' ')) | Set-Content -LiteralPath "$work/nginx.conf"
Write-Host "Site: $site"
} finally {
$outputLock.Dispose()
Expand Down
55 changes: 55 additions & 0 deletions framework-views/DocfxHttpErrors.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
function New-DocfxHttpErrors([string] $Stage, $Build, [string] $ApiPath) {
$source = "$Stage/framework-template/http-errors"
New-Item -ItemType Directory -Path $source | Out-Null
$template = Get-Content -LiteralPath "$PSScriptRoot/http-error.md.tmpl" -Raw
$errors = @(
,@(400, 'Bad Request', 'Check the documentation address and any selected framework.')
,@(401, 'Unauthorized', 'Sign in with an account that has access to this documentation.')
,@(403, 'Forbidden', 'Your current access does not allow you to open this page.')
,@(404, 'Not Found', 'The documentation page may have moved or the address may be incorrect.')
,@(405, 'Method Not Allowed', 'Open the documentation page directly in your browser.')
,@(408, 'Request Timeout', 'The request took too long to arrive. Try opening the page again.')
,@(410, 'Gone', 'This documentation page has been removed. Search for its replacement.')
,@(412, 'Precondition Failed', 'Open the page again to request its current version.')
,@(413, 'Content Too Large', 'The request is too large. Try opening the page directly.')
,@(414, 'URI Too Long', 'Shorten the address or search for the page from the documentation home.')
,@(415, 'Unsupported Media Type', 'Open the documentation page directly in your browser.')
,@(416, 'Range Not Satisfiable', 'Open the page again to request the complete document.')
,@(429, 'Too Many Requests', 'Wait a moment before making another request.')
,@(500, 'Internal Server Error', 'The page could not be served. Try again in a moment.')
,@(501, 'Not Implemented', 'This request is unsupported. Open the page directly in your browser.')
,@(502, 'Bad Gateway', 'The documentation is temporarily unavailable. Try again in a moment.')
,@(503, 'Service Unavailable', 'The documentation is temporarily unavailable. Try again in a moment.')
,@(504, 'Gateway Timeout', 'The request took too long to complete. Try again in a moment.')
,@(505, 'HTTP Version Not Supported', 'Open the documentation in a current browser.')
)
foreach ($errorPage in $errors) {
$code, $heading, $message = $errorPage
$page = $template.Replace('__STATUS__', $code).Replace('__HEADING__', $heading).
Replace('__MESSAGE__', $message).Replace('__API_PATH__', "/$ApiPath/")
Set-Content -LiteralPath "$source/$code.md" -Value $page
$code
}
$Build.content = @($Build['content'] ?? @()) + @{ src = 'framework-template/http-errors'; dest = '_docfx-errors'; files = @('*.md') }
}

function Complete-DocfxHttpErrors([string] $Site, [int[]] $Statuses) {
# Compatible templates load this asset on documentation pages, where the recovery script records the last page.
Add-Content -LiteralPath "$Site/public/framework-view.js" -Value ("`n" + (Get-Content -LiteralPath "$PSScriptRoot/http-error.js" -Raw))
Copy-Item -LiteralPath "$PSScriptRoot/http-error.js" -Destination "$Site/public/docfx-http-error.js"
$head = @'
$0
<base href="/_docfx-errors/">
<meta name="robots" content="noindex">
<meta name="referrer" content="no-referrer">
<script defer src="/public/docfx-http-error.js"></script>
'@
foreach ($status in $Statuses) {
$path = "$Site/_docfx-errors/$status.html"
$html = Get-Content -LiteralPath $path -Raw
# Modern DocFX resolves these against location.href, independently of the HTML base URL.
$html = $html -creplace '(<meta name="docfx:(?:navrel|tocrel|rel)" content=")\.\./', '$1/'
$html -creplace '<html\s*>', '<html lang="en">' -creplace '<head(?:\s[^>]*)?>', $head |
Set-Content -LiteralPath $path -NoNewline
}
}
127 changes: 126 additions & 1 deletion framework-views/FrameworkViewConventions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function Get-ApiPath($Metadata) {
if (!$length) { throw 'Metadata destinations have no common API directory. Put all metadata.dest paths under one directory in docfx.json.' }
$common = $common[0..($length - 1)]
}
if ($common[0] -in 'public', '_frameworks', '_framework-search') {
if ($common[0] -in 'public', '_frameworks', '_framework-search', '_docfx-errors') {
throw "Metadata destinations use the reserved directory '$($common[0])'. Choose a different API directory in docfx.json."
}
$common -join '/'
Expand Down Expand Up @@ -83,3 +83,128 @@ function Get-FrameworkOutputEntries([string] $Path, [string] $OwnershipFile, [st
$links = Get-ChildItem -LiteralPath $Path -Force -Recurse -Attributes ReparsePoint | Select-Object -First 1
if ($links) { throw "Framework output contains a link. Move '$($links.FullName)' before rebuilding." }
}

function Get-FrameworkPageAvailability([string] $SiteRoot, [string] $ApiPath, [string] $DefaultView, $Views) {
$pageViews = [Collections.Generic.Dictionary[string, Collections.Generic.List[string]]]::new([StringComparer]::Ordinal)
foreach ($view in $Views.Keys) {
$viewApiRoot = if ($view -ceq $DefaultView) {
Join-Path $SiteRoot $ApiPath
} else {
Join-Path $SiteRoot "_frameworks/$($Views[$view].directory)/$ApiPath"
}
if (!(Test-Path -LiteralPath $viewApiRoot -PathType Container)) { continue }
foreach ($file in [IO.Directory]::EnumerateFiles($viewApiRoot, '*.html', [IO.SearchOption]::AllDirectories)) {
$relative = [IO.Path]::GetRelativePath($viewApiRoot, $file).Replace('\', '/')
if (!$pageViews.ContainsKey($relative)) {
$pageViews[$relative] = [Collections.Generic.List[string]]::new()
}
$pageViews[$relative].Add($view)
}
}

$setIndexes = [Collections.Generic.Dictionary[string, int]]::new([StringComparer]::Ordinal)
$sets = [Collections.Generic.List[string[]]]::new()
$pages = [Collections.Specialized.OrderedDictionary]::new([StringComparer]::Ordinal)
$sortedKeys = [string[]]$pageViews.Keys
[Array]::Sort($sortedKeys, [StringComparer]::Ordinal)
foreach ($relative in $sortedKeys) {
$available = $pageViews[$relative].ToArray()
$key = $available -join ','
if (!$setIndexes.ContainsKey($key)) {
$setIndexes[$key] = $sets.Count
$sets.Add($available)
}
$pages[$relative] = $setIndexes[$key]
}
[ordered]@{ sets = $sets.ToArray(); pages = $pages }
}

function Get-FrameworkNginxFallbackRules([string] $DefaultView, $Views) {
foreach ($view in $Views.Keys) {
$prefix = if ($view -ceq $DefaultView) { '' } else { "/_frameworks/$($Views[$view].directory)" }
' if (-f $document_root{0}$framework_fallback_target) {{ return 302 $uri?${{framework_query_prefix}}view={1}; }}' -f $prefix, $view
}
}

function Resolve-FrameworkApiRelativePage([string] $Href, [string] $ApiPrefix) {
if (!$Href) { return $null }
$normalized = ($Href -split '[?#]', 2)[0].TrimStart('/')
if (!$normalized.StartsWith($ApiPrefix, [StringComparison]::Ordinal)) { return $null }
$relative = $normalized.Substring($ApiPrefix.Length)
if (!$relative -or $relative.EndsWith('/')) { "${relative}index.html" } else { $relative }
}

function Get-NavigationTocIdentityHref([string] $Href) {
# DocFX can leave an API source link unresolved in one view and render it as HTML in another.
$Href -creplace '^/(?!/)', '' -creplace '^([^?#]+)\.yml(?=[?#]|$)', '$1.html'
}

function Merge-NavigationTocItems($TargetItems, $CandidateItemLists, [string] $ApiPrefix, $Availability) {
$changed = $false
if (!$TargetItems) { return $false }
foreach ($item in $TargetItems) {
$relative = Resolve-FrameworkApiRelativePage $item['href'] $ApiPrefix
$needsDestination = $relative -and !$Availability.pages.Contains($relative)
if (!$needsDestination -and !$item['items']) { continue }

$name = $item['name']
if ([string]::IsNullOrWhiteSpace($name)) { continue }
$identityHref = Get-NavigationTocIdentityHref $item['href']
$sameIdentity = {
[string]::Equals($_['name'], $name, [StringComparison]::Ordinal) -and
[string]::Equals((Get-NavigationTocIdentityHref $_['href']), $identityHref, [StringComparison]::Ordinal)
}
if (@($TargetItems | Where-Object $sameIdentity).Count -ne 1) { continue }
$candidates = @(
foreach ($candidateList in $CandidateItemLists) {
if (!$candidateList) { continue }
$matchingItems = @($candidateList | Where-Object $sameIdentity)
if ($matchingItems.Count -eq 1) { $matchingItems[0] }
}
)

if ($needsDestination) {
foreach ($candidate in $candidates) {
$candidateHref = $candidate['href']
$candidateRelative = Resolve-FrameworkApiRelativePage $candidateHref $ApiPrefix
if ($candidateRelative -and $Availability.pages.Contains($candidateRelative)) {
$item['href'] = $candidateHref
foreach ($field in 'topicHref', 'tocHref') {
if ($candidate.Contains($field)) { $item[$field] = $candidate[$field] }
}
$changed = $true
break
}
}
}
if ($item['items']) {
$childCandidates = @(
foreach ($candidate in $candidates) {
if ($candidate['items']) { , $candidate['items'] }
}
)
if (Merge-NavigationTocItems $item['items'] $childCandidates $ApiPrefix $Availability) { $changed = $true }
}
}
$changed
}

function Merge-SharedNavigationToc([string] $SiteRoot, [string] $WorkRoot, [string] $BuildDestination, [string] $ApiPath, [string] $DefaultView, $Views, $Availability) {
$tocPath = Join-Path $SiteRoot 'toc.json'
if (!(Test-Path -LiteralPath $tocPath -PathType Leaf)) { return }
$targetToc = Read-Json $tocPath
if (!$targetToc -or !$targetToc.Contains('items')) { return }
$candidateLists = @(
foreach ($view in $Views.Keys) {
if ($view -ceq $DefaultView) { continue }
$candidatePath = Join-Path $WorkRoot "$($Views[$view].directory)/$BuildDestination/toc.json"
if (!(Test-Path -LiteralPath $candidatePath -PathType Leaf)) { continue }
$candidateToc = Read-Json $candidatePath
if ($candidateToc -and $candidateToc.Contains('items')) { , $candidateToc['items'] }
}
)
if (!$candidateLists.Count) { return }
if (Merge-NavigationTocItems $targetToc['items'] $candidateLists "$ApiPath/" $Availability) {
Write-Json $tocPath $targetToc
}
}
Loading