@@ -224,17 +224,23 @@ $(($successfulCommands | ForEach-Object { "- ``$($_.CommandName)`` `n" }) -join
224224 }
225225
226226 Write-Host ' ::group::Build docs - Move markdown files from public functions folder to docs output folder'
227- # Folders that already provide an explicit index page (any casing of index.md); a sibling
228- # <Group>.md in such a folder stays a normal page so it never overwrites the author-provided
229- # index page. Detected case-insensitively because the runner filesystem is case-sensitive.
230- $explicitIndexFolders = @ (
231- Get-ChildItem - Path $PublicFunctionsFolder - Recurse - Force - File |
232- Where-Object { $_.Name -ieq ' index.md' } |
233- ForEach-Object { $_.Directory.FullName } |
234- Sort-Object - Unique
235- )
236- Get-ChildItem - Path $PublicFunctionsFolder - Recurse - Force - Include ' *.md' | ForEach-Object {
237- $file = $_
227+ # Enumerate the public markdown once and reuse it (no second tree walk).
228+ $publicMarkdownFiles = @ (Get-ChildItem - Path $PublicFunctionsFolder - Recurse - Force - File - Include ' *.md' )
229+
230+ # Folders that provide an explicit index page. Detected case-insensitively because the runner
231+ # filesystem is case-sensitive. Two index pages that differ only by case (index.md and
232+ # Index.md) are ambiguous, so fail fast instead of silently overwriting one.
233+ $explicitIndexFolders = [System.Collections.Generic.HashSet [string ]]::new()
234+ $indexGroups = $publicMarkdownFiles | Where-Object { $_.Name -ieq ' index.md' } | Group-Object { $_.Directory.FullName }
235+ foreach ($group in $indexGroups ) {
236+ if ($group.Count -gt 1 ) {
237+ $names = ($group.Group.Name | Sort-Object ) -join ' , '
238+ throw " Ambiguous section index in '$ ( $group.Name ) ': multiple index pages ($names ). Keep only one index.md."
239+ }
240+ [void ]$explicitIndexFolders.Add ($group.Name )
241+ }
242+
243+ foreach ($file in $publicMarkdownFiles ) {
238244 $relPath = [System.IO.Path ]::GetRelativePath($PublicFunctionsFolder.FullName , $file.FullName )
239245 Write-Host " - $relPath "
240246 Write-Host " Path: $file "
@@ -252,7 +258,7 @@ $(($successfulCommands | ForEach-Object { "- ``$($_.CommandName)`` `n" }) -join
252258 $docsFilePath = Join-Path - Path (Split-Path - Path $docsFilePath - Parent) - ChildPath ' index.md'
253259 Write-Host ' Section index page detected - publishing as index.md'
254260 } elseif ($file.BaseName -eq $parentFolderName ) {
255- if ($parentFolder -in $ explicitIndexFolders ) {
261+ if ($explicitIndexFolders.Contains ( $parentFolder ) ) {
256262 Write-Warning " Ignoring group overview '$relPath ' as the section index; folder already has an explicit index.md."
257263 } else {
258264 $docsFilePath = Join-Path - Path (Split-Path - Path $docsFilePath - Parent) - ChildPath ' index.md'
0 commit comments