11Param (
2- [Parameter (HelpMessage = " Where to output docs" )]
3- [string ]$OutputDir = " docs"
2+ [Parameter (HelpMessage = " Where to output docs" )]
3+ [string ]$OutputDir = " docs"
44)
55
66$tocContents = " items:`n "
@@ -15,7 +15,7 @@ foreach ($componentFolder in Get-ChildItem -Path $componentsRoot -Directory) {
1515 $tocContents = $tocContents + " - name: $componentName `n items:`n "
1616
1717 # Find each markdown file in component's samples folder
18- foreach ($markdownFile in Get-ChildItem - Recurse - Path " $componentFolder /samples/**/*.md" | Where-Object {$_.FullName -notlike " *\bin\*" -and $_FullName -notlike " *\obj\*" }) {
18+ foreach ($markdownFile in Get-ChildItem - Recurse - Path " $componentFolder /samples/**/*.md" | Where-Object { $_.FullName -notlike " *\bin\*" -and $_FullName -notlike " *\obj\*" }) {
1919 $contents = Get-Content $markdownFile - Raw
2020
2121 # Find title
@@ -27,22 +27,19 @@ foreach ($componentFolder in Get-ChildItem -Path $componentsRoot -Directory) {
2727 $endIndex = $contents | Select-String - Pattern " ---" - AllMatches | ForEach-Object { $_.Matches [1 ].Index }
2828
2929 # Insert Header
30- $contents = $contents.Substring (0 , $endIndex + 5 ) + " `n # $header `n " + $contents.Substring ($endIndex + 5 )
30+ $contents = $contents.Substring (0 , $endIndex + 5 ) + " `n # $header `n " + $contents.Substring ($endIndex + 5 )
3131
3232 # Find Sample Placeholders, replace with code content
33- foreach ($sample in ($contents | Select-String - Pattern ' >\s*\[!SAMPLE\s*(?<sampleid>.*)\s*\]\s*' - AllMatches).Matches)
34- {
33+ foreach ($sample in ($contents | Select-String - Pattern ' >\s*\[!SAMPLE\s*(?<sampleid>.*)\s*\]\s*' - AllMatches).Matches) {
3534 $sampleid = $sample.Groups [1 ].Value
3635 $sampleString = $sample.Groups [0 ].Value
3736
3837 # Find matching filename for CS
3938 foreach ($csFile in Get-ChildItem - Recurse - Path ($markdownFile.DirectoryName + ' \**\*.xaml.cs' ).Replace(' \' , ' /' ) |
40- Where-Object {$_.FullName -notlike " *\bin\*" -and $_FullName -notlike " *\obj\*" })
41- {
39+ Where-Object { $_.FullName -notlike " *\bin\*" -and $_FullName -notlike " *\obj\*" }) {
4240 $csSample = Get-Content $csFile - Raw
4341
44- if ($csSample -match ' \[ToolkitSample\s?\(\s*id:\s*(?:"|nameof\()\s?' + $sampleid + ' \s?(?:"|\))' )
45- {
42+ if ($csSample -match ' \[ToolkitSample\s?\(\s*id:\s*(?:"|nameof\()\s?' + $sampleid + ' \s?(?:"|\))' ) {
4643 # Get Relative Path
4744 $docPath = $ (Join-Path " components" $ ($csfile.FullName.Replace ($componentsRoot.Path , ' ' ))).Replace(' \' , ' /' ).Trim(' /' )
4845
@@ -59,15 +56,22 @@ foreach ($componentFolder in Get-ChildItem -Path $componentsRoot -Directory) {
5956
6057 # Make any learn links relative
6158 $contents = $contents.Replace (' https://learn.microsoft.com' , ' ' )
62-
63- # create output directory if it doesn't exist
59+
6460 $mdOutputPath = Join-Path $OutputDir $componentName
6561
6662 if (-not (Test-Path $mdOutputPath )) {
6763 New-Item - ItemType Directory - Path $mdOutputPath | Out-Null
6864 }
6965
70- $mdOutputFile = Join-Path $mdOutputPath $markdownFile.Name
66+ $markdownFileName = $markdownFile.Name
67+
68+ # If the file is named the same as the component, rename it to index.md
69+ # This is so that the URL for the component is /componentName instead of /componentName/componentName
70+ if ($markdownFileName -eq " $componentName .md" ) {
71+ $markdownFileName = " index.md"
72+ }
73+
74+ $mdOutputFile = Join-Path $mdOutputPath $markdownFileName
7175
7276 # Write file contents
7377 Write-Host ' Writing File:' , $mdOutputFile
0 commit comments