-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathCreateEmbeddedDocs.ps1
More file actions
156 lines (132 loc) · 4.45 KB
/
CreateEmbeddedDocs.ps1
File metadata and controls
156 lines (132 loc) · 4.45 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# error to break
trap { break }
$ErrorActionPreference = "stop"
function Get-JekyllSource {
[CmdletBinding()]
param (
[Parameter(Mandatory = $True, ValueFromPipeline = $True)]
[object[]]$Content,
[string]$Title
)
begin {
$phase = 0
Write-Output "---"
Write-Output "layout: default"
Write-Output "title: $Title"
Write-Output "---"
Write-Output ""
}
process {
foreach ($line in $Content) {
if ($phase -eq 0) {
if ($line -match "<body>(.*)$") {
Write-Output $Matches[1]
$phase ++
}
}
elseif ($phase -eq 1) {
if ($line -match "^(.*)</body>") {
Write-Output $Matches[1]
$phase ++
}
else {
Write-Output $line
}
}
}
}
}
function Get-Title {
param (
$Content
)
foreach ($line in $Content) {
if ($line -match "<h1>\s*(.+)\s*</h1>") {
return $Matches[1]
}
}
return "no title"
}
function Get-TrimmedNeeViewHeading {
[CmdletBinding()]
param (
[Parameter(Mandatory = $True, ValueFromPipeline = $True)]
[object[]]$Content
)
process {
$regex = "<h1>\s*(NeeView\s*)?(.+)</h1>"
foreach ($line in $Content) {
if ($line -match $regex) {
$title = $Matches[2].Trim()
$title = $title.Substring(0, 1).ToUpper() + $title.Substring(1)
$line -replace $regex, "<h1>$title</h1>"
}
else {
$line
}
}
}
}
function Get-FixedCommandList {
[CmdletBinding()]
param (
[Parameter(Mandatory = $True, ValueFromPipeline = $True)]
[object[]]$Content,
[string]$Culture
)
begin {
$phase = 0
}
process {
foreach ($line in $Content) {
if ($phase -eq 0) {
if ($line -match "^<!-- section:\s*([^\s]+)\s*-->") {
$section = $Matches[1]
if ($section -eq "note") {
$phase = 1
if ($Culture -eq "ja-jp") {
Write-Output "<p>このリストのキー設定はプリセット TypeA です。</p>"
}
else {
Write-Output "<p>The key setting for this listing is preset TypeA.</p>"
}
continue
}
}
}
elseif ($phase -eq 1) {
if ($line -match "^<!-- section_end:\s*([^\s]+)\s*-->") {
$phase = 2
}
continue
}
Write-Output $line
}
}
}
function Write-CultureDocs {
param ([string]$culture)
$output = "docs\$culture"
Copy-Item "$neeview_profile\CommandLineOptions.$culture.md" "docs\$culture\commandline-options.md"
$content = Get-Content "$neeview_profile\CommandList.$culture.html" | Get-TrimmedNeeViewHeading | Get-FixedCommandList -Culture $culture
$title = Get-Title $content
$content | Get-JekyllSource -Title $title > "$output\command-list.html"
$content = Get-Content "$neeview_profile\MainMenu.$culture.html" | Get-TrimmedNeeViewHeading
$title = Get-Title $content
$content | Get-JekyllSource -Title $title > "$output\main-menu.html"
$content = Get-Content "$neeview_profile\ScriptManual.$culture.html" | Get-TrimmedNeeViewHeading
$title = Get-Title $content
$content | Get-JekyllSource -Title $title > "$output\script-manual.html"
$content = Get-Content "$neeview_profile\SearchOptionManual.$culture.html" | Get-TrimmedNeeViewHeading
$title = Get-Title $content
$content | Get-JekyllSource -Title $title > "$output\search-options.html"
}
$neeview = "NeeView\bin\x64\Debug\net9.0-windows"
$neeview_profile = "$neeview\Profile"
Write-Host "Create en-us Embedded Documents..."
Start-Process -FilePath "$neeview\NeeView.exe" -Wait -WindowStyle Minimized -ArgumentList "--debug=export-docs -l en -n"
Write-Host "Create ja-jp Embedded Documents..."
Start-Process -FilePath "$neeview\NeeView.exe" -Wait -WindowStyle Minimized -ArgumentList "--debug=export-docs -l ja -n"
Write-Host "Export for docs."
Write-CultureDocs "en-us"
Write-CultureDocs "ja-jp"