Skip to content

Commit d5b0b06

Browse files
hubwritersarahs
andauthored
Fix the 'Expand All' button in the all-site ToC (#56439)
Co-authored-by: Sarah Schneider <sarahs@github.com>
1 parent eee4f71 commit d5b0b06

File tree

4 files changed

+41
-42
lines changed

4 files changed

+41
-42
lines changed

src/dev-toc/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,33 @@
11
# Developer table of contents
22

33
This directory generates a full table of contents for the docs.github.com site.
4+
5+
<img src="toc-screenshot.png" width=30% style="padding-bottom: 2em" />
6+
7+
The table of contents is generated locally within the `static` subdirectory as a series of `index.html` files, within version subdirectories such as `free-pro-team@latest` and `enterprise-cloud@latest` etc.
8+
9+
## Generating the table of contents
10+
11+
To generate the table of contents, run the following command from the Terminal:
12+
13+
```bash
14+
npm run dev-toc
15+
```
16+
17+
After generating the files, the ToC should open in your default browser. If it doesn't, open your browser and naviate to `file:///PATH/TO/docs-internal/src/dev-toc/static/free-pro-team@latest/index.html`.
18+
19+
## Generating the ToC with one or more sections auto-expanded
20+
21+
Alternatively, you can generate the table of contents with a specific top-level section of the docs auto-expanded by running the following command:
22+
23+
```bash
24+
tsx src/dev-toc/generate.ts -o PRODUCT-ID [PRODUCT-ID PRODUCT-ID ...]
25+
```
26+
27+
where `PRODUCT-ID` is the first part of the URL for the top-level section of the docs. For example, the `actions` section of the docs has the URL `https://docs.github.com/en/actions`, so the `PRODUCT-ID` is `actions`. So the command would be:
28+
29+
```bash
30+
tsx src/dev-toc/generate.ts -o actions
31+
```
32+
33+
Note: if you generate the table more than once, with a different product ID flag you will need to refresh the page to see the changes.

src/dev-toc/index.ts

Lines changed: 0 additions & 41 deletions
This file was deleted.

src/dev-toc/layout.html

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,17 @@ <h2 class="mt-3 mb-3"><abbr>TOC</abbr> for {{ allVersions[currentVersion].versio
6161
{% endfor %}
6262
{% endif %}
6363

64-
<script src="../../index.js"></script>
64+
<script>
65+
const expandBtn = document.querySelector('.js-expand');
66+
expandBtn?.addEventListener('click', function() {
67+
const details = document.querySelectorAll('details');
68+
const shouldExpand = expandBtn.textContent.trim() === 'Expand All';
69+
details.forEach(detail => {
70+
detail.open = shouldExpand;
71+
});
72+
expandBtn.textContent = shouldExpand ? 'Collapse All' : 'Expand All';
73+
});
74+
</script>
6575
</main>
6676
</body>
6777
</html>

src/dev-toc/toc-screenshot.png

197 KB
Loading

0 commit comments

Comments
 (0)