Skip to content

Commit 9d55145

Browse files
Address review: case-insensitive index detection, normalize casing, warn on collision
Detect explicit index pages case-insensitively (Where-Object -ieq) with de-duplication for case-sensitive runners; normalize any casing of index.md (Index.md/INDEX.md) to index.md in the output so MkDocs treats it as the section index; and emit a warning (instead of a silent overwrite) when a <Group>.md and an index.md coexist. Adds a Widgets/Index.md fixture to cover the casing path on Linux.
1 parent 465e074 commit 9d55145

3 files changed

Lines changed: 26 additions & 10 deletions

File tree

.github/workflows/Action-Test.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,10 @@ jobs:
6464
shell: pwsh
6565
run: |
6666
$docs = 'tests/srcTestRepo/outputs/docs'
67-
$expected = @('PSModule/index.md', 'SomethingElse/index.md')
68-
$unexpected = @('PSModule/PSModule.md', 'SomethingElse/SomethingElse.md')
67+
# PSModule: <Group>/<Group>.md mapped to index.md. SomethingElse: explicit index.md
68+
# passthrough. Widgets: Index.md normalized to index.md (case-insensitive).
69+
$expected = @('PSModule/index.md', 'SomethingElse/index.md', 'Widgets/index.md')
70+
$unexpected = @('PSModule/PSModule.md', 'SomethingElse/SomethingElse.md', 'Widgets/Index.md')
6971
$failed = $false
7072
foreach ($rel in $expected) {
7173
if (Test-Path (Join-Path $docs $rel)) { Write-Host "OK present: $rel" }

src/helpers/Build-PSModuleDocumentation.ps1

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,14 @@ $(($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.md; a sibling <Group>.md in such a folder
228-
# stays a normal page so it never overwrites the author-provided index.md.
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.
229230
$explicitIndexFolders = @(
230-
Get-ChildItem -Path $PublicFunctionsFolder -Recurse -Force -Filter 'index.md' |
231-
ForEach-Object { $_.Directory.FullName }
231+
Get-ChildItem -Path $PublicFunctionsFolder -Recurse -Force -File |
232+
Where-Object { $_.Name -ieq 'index.md' } |
233+
ForEach-Object { $_.Directory.FullName } |
234+
Sort-Object -Unique
232235
)
233236
Get-ChildItem -Path $PublicFunctionsFolder -Recurse -Force -Include '*.md' | ForEach-Object {
234237
$file = $_
@@ -243,11 +246,18 @@ $(($successfulCommands | ForEach-Object { "- ``$($_.CommandName)`` `n" }) -join
243246
# can either name it after the folder (e.g. Auth/Auth.md) or provide Auth/index.md directly.
244247
$parentFolder = Split-Path -Path $file.FullName -Parent
245248
$parentFolderName = Split-Path -Path $parentFolder -Leaf
246-
if ($file.Name -eq 'index.md') {
247-
Write-Host ' Section index page (index.md) - publishing as-is'
248-
} elseif ($file.BaseName -eq $parentFolderName -and $parentFolder -notin $explicitIndexFolders) {
249+
if ($file.Name -ieq 'index.md') {
250+
# Normalize any casing (Index.md/INDEX.md) to index.md so it is treated as the
251+
# section index on case-sensitive filesystems.
249252
$docsFilePath = Join-Path -Path (Split-Path -Path $docsFilePath -Parent) -ChildPath 'index.md'
250-
Write-Host ' Group overview page detected - publishing as section index (index.md)'
253+
Write-Host ' Section index page detected - publishing as index.md'
254+
} elseif ($file.BaseName -eq $parentFolderName) {
255+
if ($parentFolder -in $explicitIndexFolders) {
256+
Write-Warning "Group overview page '$relPath' is not used as the section index because the folder already has an explicit index.md; publishing it as a normal page."
257+
} else {
258+
$docsFilePath = Join-Path -Path (Split-Path -Path $docsFilePath -Parent) -ChildPath 'index.md'
259+
Write-Host ' Group overview page detected - publishing as section index (index.md)'
260+
}
251261
}
252262

253263
Write-Host " MD path: $docsFilePath"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Widgets
2+
3+
This is the section overview for the Widgets group, authored as `Index.md` to verify
4+
case-insensitive detection and normalization to `index.md`.

0 commit comments

Comments
 (0)