@@ -11,13 +11,25 @@ Set-Location $PSScriptRoot;
1111
1212$OutputDir = Join-Path $preWorkingDir $OutputDir
1313
14+ $lastComponent = " "
15+ $tocContents = " items:`n "
16+
1417# Find all Markdown documents
1518foreach ($markdownFile in Get-ChildItem - Recurse - Path ' ../../components/*/samples/**/*.md' |
1619 Where-Object {$_.FullName -notlike " *\bin\*" -and $_FullName -notlike " *\obj\*" }) {
1720 $contents = Get-Content $markdownFile - Raw
1821
1922 $filePath = $markdownFile.FullName.Substring ($preWorkingDir.Path.Length ).Replace(' \' , ' /' ).Trim(' /' )
2023
24+ # Get Component Name
25+ $componentsRoot = $filePath.Replace (' components/' , ' ' )
26+ $componentName = $componentsRoot.Substring (0 , $componentsRoot.IndexOf (' /' ))
27+ if ($componentName -ne $lastComponent )
28+ {
29+ $tocContents = $tocContents + " - name: $componentName `n items:`n "
30+ $lastComponent = $componentName
31+ }
32+
2133 # Find title
2234 $contents -match ' title:\s*(?<title>.*)' | Out-Null
2335
@@ -49,7 +61,7 @@ foreach ($markdownFile in Get-ChildItem -Recurse -Path '../../components/*/sampl
4961 # See https://learn.microsoft.com/en-us/contribute/content/code-in-docs#out-of-repo-snippet-references
5062 $snippet = ' :::code language="xaml" source="~/../code-windows/' + $docPath.Substring (0 , $docPath.Length - 3 ) + ' ":::' + " `n`n "
5163
52- $snippet = $snippet + ' :::code language="csharp" source="~/../code-windows/' + $docPath + ' ":::'
64+ $snippet = $snippet + ' :::code language="csharp" source="~/../code-windows/' + $docPath + ' ":::' + " `n`n "
5365
5466 # Replace our Sample Placeholder with references for docs
5567 $contents = $contents.Replace ($sampleString , $snippet )
@@ -61,12 +73,20 @@ foreach ($markdownFile in Get-ChildItem -Recurse -Path '../../components/*/sampl
6173 $contents = $contents.Replace (' https://learn.microsoft.com' , ' ' )
6274
6375 # create output directory if it doesn't exist
64- $outputFile = (Join-Path $OutputDir $filePath.Replace (' components' , ' ' ).Replace(' samples' , ' ' ).Replace(' \\' , ' \' ))
76+ $targetFile = $filePath.Replace (' components' , ' ' ).Replace(' samples' , ' ' ).Replace(' //' , ' /' )
77+ $outputFile = (Join-Path $OutputDir $targetFile )
6578 [System.IO.Directory ]::CreateDirectory((Split-Path $outputFile )) | Out-Null
6679
6780 # Write file contents
6881 Write-Host ' Writing File:' , $outputFile
6982 $contents | Set-Content $outputFile
83+
84+ # Add to TOC
85+ $targetFile = $targetFile.Trim (' /' ) # need to remove initial / from path
86+ $tocContents = $tocContents + " - name: $header `n href: $targetFile `n "
7087}
7188
89+ Write-Host ' Writing TOC'
90+ $tocContents | Set-Content (Join-Path $OutputDir " TOC.yml" )
91+
7292Set-Location $preWorkingDir ;
0 commit comments