Skip to content

Commit 9236898

Browse files
committed
add support for passing an option to open sections by default
1 parent f039256 commit 9236898

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

script/dev-toc/generate.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import fs from 'fs'
44
import path from 'path'
55
import { execSync } from 'child_process'
6+
import { program } from 'commander'
67
import fpt from '../../lib/non-enterprise-default-version.js'
78
import { allVersionKeys } from '../../lib/all-versions.js'
89
import { liquid } from '../../lib/render-content/index.js'
@@ -15,6 +16,19 @@ const staticDirName = 'script/dev-toc/static'
1516
const staticDir = path.posix.join(process.cwd(), staticDirName)
1617
if (!fs.existsSync(staticDir)) fs.mkdirSync(staticDir)
1718

19+
program
20+
.description('Generate a local TOC of the docs website and open it in your browser')
21+
.option(
22+
'-o, --openSections [product-ids...]',
23+
'open sections for one or more product IDs by default (e.g., "-o codespaces pull-requests")'
24+
)
25+
.parse(process.argv)
26+
27+
const options = program.opts()
28+
29+
const openSections = options.openSections || ''
30+
const defaultOpenSections = Array.isArray(openSections) ? openSections : [openSections]
31+
1832
main()
1933

2034
async function main() {
@@ -38,6 +52,9 @@ async function main() {
3852
// Add the tree to the req.context.
3953
req.context.currentEnglishTree = req.context.siteTree.en[req.context.currentVersion]
4054

55+
// Add any defaultOpenSections to the context.
56+
req.context.defaultOpenSections = defaultOpenSections
57+
4158
// Parse the layout in script/dev-toc/layout.html with the context we created above.
4259
const outputHtml = await liquid.parseAndRender(layout, Object.assign({}, req.context))
4360

script/dev-toc/layout.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ <h2 class="mt-3 mb-3"><abbr>TOC</abbr> for {{ allVersions[currentVersion].versio
2525
<div/>
2626

2727
{% 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 %}
2832
<details class="mb-1"><summary>{{productPage.renderedFullTitle}}</summary>
33+
{% endif %}
2934
<ul class="products-list">
3035
<li title="{{productPage.renderedFullTitle}}" style="margin: 3px 0 0 30px;">
3136
<a title="{{ productPage.page.documentType }}" href="{{ docsRoot }}{{productPage.href}}">{{ productPage.renderedFullTitle }}</a>

0 commit comments

Comments
 (0)