-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathExport.ps1
More file actions
67 lines (57 loc) · 1.89 KB
/
Copy pathExport.ps1
File metadata and controls
67 lines (57 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<#
.SYNOPSIS
Exports the PowerShell guide.
.DESCRIPTION
Export all files in the PowerShell guide.
#>
param(
$OutputPath
)
if (-not $OutputPath) {
$OutputPath =
Get-Module PowerShellGuide |
Select-Object -first 1 |
Split-Path |
Join-Path -ChildPath 'docs'
}
$allTopicMetadata = @()
foreach ($topic in $this.AllTopics) {
$relativePathParts = @($topic.RelativePath.Split([IO.Path]::DirectorySeparatorChar))
$targetPathRoot = $OutputPath
if ($relativePathParts.Length -gt 1) {
for (
$pathPartIndex = 0;
$pathPartIndex -lt ($relativePathParts.Length - 1);
$pathPartIndex++
) {
$pathPart = $relativePathParts[$pathPartIndex]
$targetPathRoot = Join-Path $targetPathRoot $pathPart
}
}
if (-not (Test-Path $targetPathRoot)) {
$null = New-Item -ItemType Directory -Path $targetPathRoot -Force
}
if ($topic.Link.Length -ne ($topic.RelativePath.Length - 3)) {
$topicMarkdownFile = Join-Path $OutputPath $topic.Link |
Join-Path -ChildPath "index.markdown"
} else {
$topicMarkdownFile = Join-Path $targetPathRoot "$($topic.TopicName -replace '[_\-\s]', '-').md"
}
$allTopicMetadata += [PSCustomObject]@{
Name = $topic.TopicName
Aliases = $topic.Aliases
Link = $topic.Link
}
$($topic |
Add-Member NoteProperty FrontMatter @{
layout ='default'
} -PassThru -Force |
Format-Custom -View Markdown |
Out-String -Width 1mb).Trim() |
Set-Content -Path $topicMarkdownFile
Get-Item $topicMarkdownFile
}
$topicMetadataPath = Join-Path $OutputPath -ChildPath "guide.json"
$allTopicMetadata | ConvertTo-Json -Depth 100 |
Set-Content -Path $topicMetadataPath
Get-Item $topicMetadataPath