1
1
Param (
2
- [Parameter (HelpMessage = " Where to output docs" )]
3
- [string ]$OutputDir = " docs"
2
+ [Parameter (HelpMessage = " Where to output docs" )]
3
+ [string ]$OutputDir = " docs"
4
4
)
5
5
6
6
$tocContents = " items:`n "
@@ -15,7 +15,7 @@ foreach ($componentFolder in Get-ChildItem -Path $componentsRoot -Directory) {
15
15
$tocContents = $tocContents + " - name: $componentName `n items:`n "
16
16
17
17
# 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\*" }) {
19
19
$contents = Get-Content $markdownFile - Raw
20
20
21
21
# Find title
@@ -27,22 +27,19 @@ foreach ($componentFolder in Get-ChildItem -Path $componentsRoot -Directory) {
27
27
$endIndex = $contents | Select-String - Pattern " ---" - AllMatches | ForEach-Object { $_.Matches [1 ].Index }
28
28
29
29
# 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 )
31
31
32
32
# 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) {
35
34
$sampleid = $sample.Groups [1 ].Value
36
35
$sampleString = $sample.Groups [0 ].Value
37
36
38
37
# Find matching filename for CS
39
38
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\*" }) {
42
40
$csSample = Get-Content $csFile - Raw
43
41
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?(?:"|\))' ) {
46
43
# Get Relative Path
47
44
$docPath = $ (Join-Path " components" $ ($csfile.FullName.Replace ($componentsRoot.Path , ' ' ))).Replace(' \' , ' /' ).Trim(' /' )
48
45
@@ -59,15 +56,22 @@ foreach ($componentFolder in Get-ChildItem -Path $componentsRoot -Directory) {
59
56
60
57
# Make any learn links relative
61
58
$contents = $contents.Replace (' https://learn.microsoft.com' , ' ' )
62
-
63
- # create output directory if it doesn't exist
59
+
64
60
$mdOutputPath = Join-Path $OutputDir $componentName
65
61
66
62
if (-not (Test-Path $mdOutputPath )) {
67
63
New-Item - ItemType Directory - Path $mdOutputPath | Out-Null
68
64
}
69
65
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
71
75
72
76
# Write file contents
73
77
Write-Host ' Writing File:' , $mdOutputFile
0 commit comments