Skip to content

Commit d4775ec

Browse files
committed
Builds table of contents, with link to jump back to top
1 parent a8220bf commit d4775ec

4 files changed

Lines changed: 349 additions & 686 deletions

File tree

source/readme.build.ps1

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,9 @@ function RenderReadmeForGroup {
162162
$GroupedBy,
163163
[string] $PathOutput,
164164

165-
[hashtable]$Options = @{}
165+
[hashtable]$Options = @{
166+
TOC = $true
167+
}
166168
)
167169
[string]$finalDocRender = ''
168170

@@ -174,6 +176,29 @@ function RenderReadmeForGroup {
174176

175177
if($Options.TOC) {
176178
$GroupedBy.Name
179+
180+
# $finalDocRender += @(
181+
# "`n`n"
182+
# "## Table of Contents"
183+
# "`n"
184+
# ) -join ''
185+
186+
[string] $renderTOC =
187+
$GroupedBy.Name
188+
| Sort-Object
189+
| %{
190+
MdFormat-Link -Name $_ -Url (Join-String -f '#{0}' -Inp $_)
191+
|Join-String -f ' - {0}'
192+
} | Join-String -sep "`n"
193+
194+
$finalDocRender += @(
195+
"`n`n"
196+
"## Table of Contents"
197+
"`n"
198+
$renderTOC
199+
"`n"
200+
) -join ''
201+
177202
}
178203

179204
$GroupedBy | %{
@@ -185,6 +210,8 @@ function RenderReadmeForGroup {
185210
"`n`n"
186211
"### ${GroupName}"
187212
"`n"
213+
'[Top](#table-of-contents)' # or: MdFormat-link -Name 'Top' -Url '#table-of-contents'
214+
"`n"
188215
) -join ''
189216

190217
$curGroup.Group | %{
@@ -210,11 +237,13 @@ function RenderReadmeForGroup {
210237
')'
211238
) -join ''
212239
#>
240+
$RendStr +=
241+
$RendMdLink | Join-String -f "`n - {0}"
213242

214-
$rendStr += @(
215-
"`n"
216-
$RendMdLink
217-
) -join ''
243+
# $rendStr += @(
244+
# "`n"
245+
# $RendMdLink
246+
# ) -join ''
218247
} # | Join-String -f "`n{0}`n"
219248

220249
$finalDocRender += $rendStr
@@ -231,9 +260,9 @@ $group_byParent = $find_pq | Group DirectoryBaseName
231260
# $group_byRelPath = $find_pq | Group RelativePath
232261
$group_byDirectory = $find_pq | Group Directory
233262

234-
RenderReadmeForGroup -GroupedBy $group_byRelpath -PathOutput 'readme.byRelpath.md'
235-
RenderReadmeForGroup -GroupedBy $group_byDirectory -PathOutput 'readme.byDirectory.md'
263+
# RenderReadmeForGroup -GroupedBy $group_byRelpath -PathOutput 'readme.byRelpath.md'
236264
RenderReadmeForGroup -GroupedBy $group_byParent -PathOutput 'readme.byParent.md'
265+
RenderReadmeForGroup -GroupedBy $group_byDirectory -PathOutput 'readme.byDirectory.md'
237266

238267
$find_pq | Select -First 7 # | FormatPqSourceItem
239268
| ft -auto

0 commit comments

Comments
 (0)