@@ -11,13 +11,25 @@ Set-Location $PSScriptRoot;
11
11
12
12
$OutputDir = Join-Path $preWorkingDir $OutputDir
13
13
14
+ $lastComponent = " "
15
+ $tocContents = " items:`n "
16
+
14
17
# Find all Markdown documents
15
18
foreach ($markdownFile in Get-ChildItem - Recurse - Path ' ../../components/*/samples/**/*.md' |
16
19
Where-Object {$_.FullName -notlike " *\bin\*" -and $_FullName -notlike " *\obj\*" }) {
17
20
$contents = Get-Content $markdownFile - Raw
18
21
19
22
$filePath = $markdownFile.FullName.Substring ($preWorkingDir.Path.Length ).Replace(' \' , ' /' ).Trim(' /' )
20
23
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
+
21
33
# Find title
22
34
$contents -match ' title:\s*(?<title>.*)' | Out-Null
23
35
@@ -49,7 +61,7 @@ foreach ($markdownFile in Get-ChildItem -Recurse -Path '../../components/*/sampl
49
61
# See https://learn.microsoft.com/en-us/contribute/content/code-in-docs#out-of-repo-snippet-references
50
62
$snippet = ' :::code language="xaml" source="~/../code-windows/' + $docPath.Substring (0 , $docPath.Length - 3 ) + ' ":::' + " `n`n "
51
63
52
- $snippet = $snippet + ' :::code language="csharp" source="~/../code-windows/' + $docPath + ' ":::'
64
+ $snippet = $snippet + ' :::code language="csharp" source="~/../code-windows/' + $docPath + ' ":::' + " `n`n "
53
65
54
66
# Replace our Sample Placeholder with references for docs
55
67
$contents = $contents.Replace ($sampleString , $snippet )
@@ -61,12 +73,20 @@ foreach ($markdownFile in Get-ChildItem -Recurse -Path '../../components/*/sampl
61
73
$contents = $contents.Replace (' https://learn.microsoft.com' , ' ' )
62
74
63
75
# 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 )
65
78
[System.IO.Directory ]::CreateDirectory((Split-Path $outputFile )) | Out-Null
66
79
67
80
# Write file contents
68
81
Write-Host ' Writing File:' , $outputFile
69
82
$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 "
70
87
}
71
88
89
+ Write-Host ' Writing TOC'
90
+ $tocContents | Set-Content (Join-Path $OutputDir " TOC.yml" )
91
+
72
92
Set-Location $preWorkingDir ;
0 commit comments