Skip to content

Commit 6fe837a

Browse files
authored
Docs site ToC: Support deeper level of article nesting (#57312)
1 parent d0b31a3 commit 6fe837a

File tree

2 files changed

+71
-31
lines changed

2 files changed

+71
-31
lines changed

src/dev-toc/generate.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
/**
2+
* Development tool that generates a local Table of Contents (TOC) for the GitHub Docs website.
3+
*
4+
* This script creates static HTML files for each documentation version, renders page titles
5+
* using Liquid templating, and opens the generated TOC in your browser for easy navigation
6+
* during development. Supports command-line options to specify which sections should be
7+
* open by default.
8+
*
9+
* Usage: tsx src/dev-toc/generate.ts [-o product-ids...]
10+
*/
11+
112
import fs from 'fs'
213
import path from 'path'
314
import { execSync } from 'child_process'

src/dev-toc/layout.html

Lines changed: 60 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -24,40 +24,69 @@ <h2 class="mt-3 mb-3"><abbr>TOC</abbr> for {{ allVersions[currentVersion].versio
2424
<button class="btn mb-3 js-expand" type="button">Expand All</button>
2525
<div/>
2626

27+
{% assign maxTocDepth = 5 %}
28+
2729
{% for productPage in currentEnglishTree.childPages %}
28-
{% assign productId = productPage.page.relativePath | replace: "/index.md", "" %}
29-
{% if defaultOpenSections contains productId %}
30-
<details open class="mb-1"><summary>{{productPage.renderedFullTitle}}</summary>
31-
{% else %}
32-
<details class="mb-1"><summary>{{productPage.renderedFullTitle}}</summary>
33-
{% endif %}
34-
<ul class="products-list">
35-
<li title="{{productPage.renderedFullTitle}}" style="margin: 3px 0 0 30px;">
36-
<a title="{{ productPage.page.documentType }}" href="{{ docsRoot }}{{productPage.href}}">{{ productPage.renderedFullTitle }}</a>
37-
{% for categoryPage in productPage.childPages %}
38-
<ul>
39-
<li style="margin: 3px 0 0 30px;">
40-
<a title="{{ categoryPage.page.documentType }}" href="{{ docsRoot }}{{ categoryPage.href }}">{{ categoryPage.renderedFullTitle }}</a>
41-
<ul>
42-
{% for subcategoryPage in categoryPage.childPages %}
30+
{% assign productId = productPage.page.relativePath | replace: "/index.md", "" %}
31+
{% if defaultOpenSections contains productId %}
32+
<details open class="mb-1"><summary>{{productPage.renderedFullTitle}}</summary>
33+
{% else %}
34+
<details class="mb-1"><summary>{{productPage.renderedFullTitle}}</summary>
35+
{% endif %}
36+
37+
<ul class="products-list">
38+
<li title="{{productPage.renderedFullTitle}}" style="margin: 3px 0 0 30px;">
39+
<a title="{{ productPage.page.documentType }}" href="{{ docsRoot }}{{productPage.href}}">{{ productPage.renderedFullTitle }}</a>
40+
41+
{% comment %} Unified nested rendering with depth control {% endcomment %}
42+
{% if productPage.childPages and productPage.childPages.size > 0 %}
43+
<ul>
44+
{% for l1 in productPage.childPages %}
4345
<li style="margin: 3px 0 0 30px;">
44-
<a title="{{ subcategoryPage.page.documentType }}" href="{{ docsRoot }}{{ subcategoryPage.href }}">{{ subcategoryPage.renderedFullTitle }}</a>
45-
<ul>
46-
{% for articlePage in subcategoryPage.childPages %}
47-
<li style="margin: 3px 0 0 30px;">
48-
<a title="{{ articlePage.page.documentType }}" href="{{ docsRoot }}{{ articlePage.href }}">{{ articlePage.renderedFullTitle }}</a>
49-
</li>
50-
{% endfor %}
51-
</ul>
46+
<a title="{{ l1.page.documentType }}" href="{{ docsRoot }}{{ l1.href }}">{{ l1.renderedFullTitle }}</a>
47+
{% if l1.childPages and l1.childPages.size > 0 and maxTocDepth >= 2 %}
48+
<ul>
49+
{% for l2 in l1.childPages %}
50+
<li style="margin: 3px 0 0 30px;">
51+
<a title="{{ l2.page.documentType }}" href="{{ docsRoot }}{{ l2.href }}">{{ l2.renderedFullTitle }}</a>
52+
{% if l2.childPages and l2.childPages.size > 0 and maxTocDepth >= 3 %}
53+
<ul>
54+
{% for l3 in l2.childPages %}
55+
<li style="margin: 3px 0 0 30px;">
56+
<a title="{{ l3.page.documentType }}" href="{{ docsRoot }}{{ l3.href }}">{{ l3.renderedFullTitle }}</a>
57+
{% if l3.childPages and l3.childPages.size > 0 and maxTocDepth >= 4 %}
58+
<ul>
59+
{% for l4 in l3.childPages %}
60+
<li style="margin: 3px 0 0 30px;">
61+
<a title="{{ l4.page.documentType }}" href="{{ docsRoot }}{{ l4.href }}">{{ l4.renderedFullTitle }}</a>
62+
{% if l4.childPages and l4.childPages.size > 0 and maxTocDepth >= 5 %}
63+
<ul>
64+
{% for l5 in l4.childPages %}
65+
<li style="margin: 3px 0 0 30px;">
66+
<a title="{{ l5.page.documentType }}" href="{{ docsRoot }}{{ l5.href }}">{{ l5.renderedFullTitle }}</a>
67+
</li>
68+
{% endfor %}
69+
</ul>
70+
{% endif %}
71+
</li>
72+
{% endfor %}
73+
</ul>
74+
{% endif %}
75+
</li>
76+
{% endfor %}
77+
</ul>
78+
{% endif %}
79+
</li>
80+
{% endfor %}
81+
</ul>
82+
{% endif %}
5283
</li>
53-
{% endfor %}
54-
</ul>
55-
</li>
56-
{% endfor %}
57-
</ul>
58-
</li>
59-
</ul>
60-
</details>
84+
{% endfor %}
85+
</ul>
86+
{% endif %}
87+
</li>
88+
</ul>
89+
</details>
6190
{% endfor %}
6291
{% endif %}
6392

0 commit comments

Comments
 (0)