Skip to content

Commit 008c490

Browse files
authored
Merge pull request #18220 from github/repo-sync
repo sync
2 parents 7a53fdc + 56f6dc8 commit 008c490

File tree

8 files changed

+47
-92
lines changed

8 files changed

+47
-92
lines changed

components/article/ToolPicker.tsx

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,10 @@ import { useArticleContext } from 'components/context/ArticleContext'
1212
// Nota bene: tool === application
1313
// Nota bene: picker === switcher
1414

15-
const supportedTools = [
16-
'cli',
17-
'desktop',
18-
'webui',
19-
'curl',
20-
'codespaces',
21-
'vscode',
22-
'importer_cli',
23-
'graphql',
24-
'powershell',
25-
'bash',
26-
]
27-
const toolTitles = {
28-
webui: 'Web browser',
29-
cli: 'GitHub CLI',
30-
curl: 'cURL',
31-
desktop: 'Desktop',
32-
codespaces: 'Codespaces',
33-
vscode: 'Visual Studio Code',
34-
importer_cli: 'GitHub Enterprise Importer CLI',
35-
graphql: 'GraphQL API',
36-
powershell: 'PowerShell',
37-
bash: 'Bash',
38-
} as Record<string, string>
39-
4015
// Imperatively modify article content to show only the selected tool
4116
// find all platform-specific *block* elements and hide or show as appropriate
4217
// example: {% webui %} block content {% endwebui %}
43-
function showToolSpecificContent(tool: string) {
18+
function showToolSpecificContent(tool: string, supportedTools: Array<string>) {
4419
const markdowns = Array.from(document.querySelectorAll<HTMLElement>('.extended-markdown'))
4520
markdowns
4621
.filter((el) => supportedTools.some((tool) => el.classList.contains(tool)))
@@ -77,7 +52,8 @@ type Props = {
7752
}
7853
export const ToolPicker = ({ variant = 'subnav' }: Props) => {
7954
const { asPath } = useRouter()
80-
const { defaultTool, detectedTools } = useArticleContext()
55+
// allTools comes from the ArticleContext which contains the list of tools available
56+
const { defaultTool, detectedTools, allTools } = useArticleContext()
8157
const [currentTool, setCurrentTool] = useState(getDefaultTool(defaultTool, detectedTools))
8258

8359
const sharedContainerProps = {
@@ -100,7 +76,7 @@ export const ToolPicker = ({ variant = 'subnav' }: Props) => {
10076
// Whenever the currentTool is changed, update the article content
10177
useEffect(() => {
10278
preserveAnchorNodePosition(document, () => {
103-
showToolSpecificContent(currentTool)
79+
showToolSpecificContent(currentTool, Object.keys(allTools))
10480
})
10581
}, [currentTool, asPath])
10682

@@ -137,7 +113,7 @@ export const ToolPicker = ({ variant = 'subnav' }: Props) => {
137113
onClickTool(tool)
138114
}}
139115
>
140-
{toolTitles[tool]}
116+
{allTools[tool]}
141117
</UnderlineNav.Link>
142118
))}
143119
</UnderlineNav>

components/context/ArticleContext.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export type ArticleContextT = {
2929
currentLearningTrack?: LearningTrack
3030
detectedPlatforms: Array<string>
3131
detectedTools: Array<string>
32+
allTools: Record<string, string>
3233
}
3334

3435
export const ArticleContext = createContext<ArticleContextT | null>(null)
@@ -70,5 +71,6 @@ export const getArticleContextFromRequest = (req: any): ArticleContextT => {
7071
currentLearningTrack: req.context.currentLearningTrack,
7172
detectedPlatforms: page.detectedPlatforms || [],
7273
detectedTools: page.detectedTools || [],
74+
allTools: page.allToolsParsed || [], // this is set at the page level, see lib/page.js
7375
}
7476
}

contributing/content-markup-reference.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ You can define a default platform in the frontmatter. For more information, see
128128

129129
## Tool tags
130130

131-
We occasionally need to write documentation for different tools (GitHub UI, GitHub CLI, GitHub Desktop, cURL, Codespaces, VS Code, GitHub Enterprise Importer CLI, GraphQL API). Each tool may require a different set of instructions. We use tool tags to demarcate information for each tool.
131+
We occasionally need to write documentation for different tools (GitHub UI, GitHub CLI, GitHub Desktop, cURL, Codespaces, VS Code, GitHub Enterprise Importer CLI, GraphQL API). Each tool may require a different set of instructions. We use tool tags to demarcate information for each tool. To modify the list of possible tools, edit [`lib/all-tools.js`](../lib/all-tools.js).
132132

133133
### Usage
134134

lib/all-tools.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// all the tools available for the Tool Picker
2+
export const allTools = {
3+
bash: 'Bash',
4+
cli: 'GitHub CLI',
5+
codespaces: 'Codespaces',
6+
curl: 'cURL',
7+
desktop: 'Dekstop',
8+
importer_cli: 'GitHub Enterprise Importer CLI',
9+
graphql: 'GraphQL API',
10+
powershell: 'PowerShell',
11+
vscode: 'Visual Studio Code',
12+
webui: 'Web browser',
13+
}

lib/frontmatter.js

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import path from 'path'
33
import parse from './read-frontmatter.js'
44
import semver from 'semver'
55
import { allVersions } from './all-versions.js'
6+
import { allTools } from './all-tools.js'
67

78
const layoutNames = [
89
'default',
@@ -20,6 +21,7 @@ const semverRange = {
2021
message: 'Must be a valid SemVer range',
2122
}
2223
const versionObjs = Object.values(allVersions)
24+
2325
const guideTypes = ['overview', 'quick_start', 'tutorial', 'how_to', 'reference']
2426
const featureVersions = fs
2527
.readdirSync(path.posix.join(process.cwd(), 'data/features'))
@@ -177,21 +179,11 @@ export const schema = {
177179
type: 'string',
178180
enum: ['mac', 'windows', 'linux'],
179181
},
180-
// Tool-specific content preference
182+
// Tool-specific content preference, the list of tools are kept in
183+
// make it easier to update in a single place
181184
defaultTool: {
182185
type: 'string',
183-
enum: [
184-
'webui',
185-
'cli',
186-
'desktop',
187-
'curl',
188-
'codespaces',
189-
'vscode',
190-
'importer_cli',
191-
'graphql',
192-
'powershell',
193-
'bash',
194-
],
186+
enum: Object.keys(allTools),
195187
},
196188
// Documentation contributed by a third party, such as a GitHub Partner
197189
contributor: {

lib/liquid-tags/extended-markdown.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
1-
export const tags = {
1+
import { allTools } from '../all-tools.js'
2+
3+
// we do this to get an object that combines all possible liquid tags
4+
const toolTags = Object.fromEntries(Object.keys(allTools).map((tool) => [tool, '']))
5+
6+
const subsetTags = {
27
mac: '',
38
windows: '',
49
linux: '',
5-
cli: '',
6-
desktop: '',
7-
webui: '',
8-
curl: '',
9-
codespaces: '',
10-
vscode: '',
11-
importer_cli: '',
12-
graphql: '',
13-
powershell: '',
14-
bash: '',
1510
all: '',
1611
tip: 'border rounded-1 mb-4 p-3 color-border-accent-emphasis color-bg-accent f5',
1712
note: 'border rounded-1 mb-4 p-3 color-border-accent-emphasis color-bg-accent f5',
1813
warning: 'border rounded-1 mb-4 p-3 color-border-danger color-bg-danger f5',
1914
danger: 'border rounded-1 mb-4 p-3 color-border-danger color-bg-danger f5',
2015
}
2116

17+
export const tags = Object.assign({}, subsetTags, toolTags)
18+
2219
export const template =
2320
'<div class="extended-markdown {{ tagName }} {{ classes }}">{{ output }}</div>'
2421

lib/page.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import readFileContents from './read-file-contents.js'
1717
import getLinkData from './get-link-data.js'
1818
import getDocumentType from './get-document-type.js'
1919
import { union } from 'lodash-es'
20+
import { allTools } from './all-tools.js'
2021

2122
// We're going to check a lot of pages' "ID" (the first part of
2223
// the relativePath) against `productMap` to make sure it's valid.
@@ -261,18 +262,13 @@ class Page {
261262
this.includesPlatformSpecificContent = this.detectedPlatforms.length > 0
262263

263264
// set flags for webui, cli, etc switcher element
264-
this.detectedTools = [
265-
'cli',
266-
'desktop',
267-
'webui',
268-
'curl',
269-
'codespaces',
270-
'vscode',
271-
`importer_cli`,
272-
`graphql`,
273-
'powershell',
274-
'bash',
275-
].filter((tool) => html.includes(`extended-markdown ${tool}`) || html.includes(`tool-${tool}`))
265+
this.detectedTools = Object.keys(allTools).filter(
266+
(tool) => html.includes(`extended-markdown ${tool}`) || html.includes(`tool-${tool}`)
267+
)
268+
269+
// pass the list of all possible tools around to components and utilities that will need it later on
270+
this.allToolsParsed = allTools
271+
276272
this.includesToolSpecificContent = this.detectedTools.length > 0
277273

278274
return html

lib/schema-event.js

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { languageKeys } from './languages.js'
22
import { allVersionKeys } from './all-versions.js'
33
import { productIds } from './all-products.js'
4-
4+
import { allTools } from './all-tools.js'
55
const context = {
66
type: 'object',
77
additionalProperties: false,
@@ -146,18 +146,7 @@ const context = {
146146
},
147147
application_preference: {
148148
type: 'string',
149-
enum: [
150-
'webui',
151-
'cli',
152-
'desktop',
153-
'curl',
154-
'codespaces',
155-
'vscode',
156-
'importer_cli',
157-
'graphql',
158-
'powershell',
159-
'bash',
160-
],
149+
enum: Object.keys(allTools),
161150
description: 'The application selected by the user.',
162151
},
163152
color_mode_preference: {
@@ -451,26 +440,16 @@ const preferenceSchema = {
451440
},
452441
preference_value: {
453442
type: 'string',
454-
enum: [
455-
'webui',
456-
'cli',
457-
'desktop',
458-
'curl',
459-
'codespaces',
460-
'vscode',
461-
'importer_cli',
462-
'graphql',
463-
'powershell',
464-
'bash',
443+
enum: Object.keys(allTools).concat(
465444
'dark',
466445
'light',
467446
'auto',
468447
'auto:dark',
469448
'auto:light',
470449
'linux',
471450
'mac',
472-
'windows',
473-
],
451+
'windows'
452+
),
474453
description: 'The application, color_mode, or os selected by the user.',
475454
},
476455
},

0 commit comments

Comments
 (0)