Skip to content

Commit 9fd4fe0

Browse files
authored
remove prerendered response rest docs (#25652)
1 parent 0d8bd53 commit 9fd4fe0

17 files changed

Lines changed: 31085 additions & 31094 deletions

components/article/ClientSideHighlightJS.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
import { useEffect } from 'react'
2+
import { useRouter } from 'next/router'
23
import hljs from 'highlight.js/lib/core'
34
import json from 'highlight.js/lib/languages/json'
5+
import javascript from 'highlight.js/lib/languages/javascript'
6+
import hljsCurl from 'highlightjs-curl'
47

58
// Add as needed. It's pretty cheap to add but please don't use
69
// highlight.js import that loads all and everything.
710
hljs.registerLanguage('json', json)
8-
const SUPPORTED_LANGUAGES = ['json']
11+
hljs.registerLanguage('javascript', javascript)
12+
hljs.registerLanguage('curl', hljsCurl)
13+
const SUPPORTED_LANGUAGES = ['json', 'javascript', 'curl']
914

1015
// This is the selector we use for the first document.querySelectorAll()
1116
// to find the containers for `<code>` tags. Because it's s dataset
@@ -24,6 +29,8 @@ const CODE_ELEMENTS_PARENT_SELECTOR = '[data-highlight]'
2429
const CODE_SELECTOR = 'pre code'
2530

2631
export default function ClientSideHighlightJS() {
32+
const { asPath } = useRouter()
33+
2734
useEffect(() => {
2835
// Hi Internet Explorer!
2936
// https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API#browser_compatibility
@@ -59,7 +66,7 @@ export default function ClientSideHighlightJS() {
5966
intersectionObserver.observe(element)
6067
}
6168
}
62-
}, [])
69+
}, [asPath])
6370

6471
return null
6572
}

components/declarations.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ declare module '*.scss' {
22
const content: Record<string, string>
33
export default content
44
}
5+
6+
declare module 'highlightjs-curl'

components/rest/CodeBlock.tsx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,12 @@ import styles from './CodeBlock.module.scss'
55
type Props = {
66
verb?: string
77
codeBlock: string
8-
setHTML?: boolean
8+
highlight?: string
99
}
1010

11-
export function CodeBlock({ verb, codeBlock, setHTML = false }: Props) {
12-
return setHTML ? (
13-
<div
14-
className={cx(styles.codeBlock, 'rounded')}
15-
dangerouslySetInnerHTML={{ __html: codeBlock }}
16-
/>
17-
) : (
18-
<pre className={cx(styles.methodCodeBlock, 'rounded-1 border')}>
11+
export function CodeBlock({ verb, codeBlock, highlight }: Props) {
12+
return (
13+
<pre className={cx(styles.methodCodeBlock, 'rounded-1 border')} data-highlight={highlight}>
1914
<code>
2015
{verb && (
2116
<span className="color-bg-accent-emphasis color-fg-on-emphasis rounded-1 text-uppercase">

components/rest/RestCodeSamples.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { xCodeSample } from './types'
1+
import type { xCodeSample } from './types'
22
import { useTranslation } from 'components/hooks/useTranslation'
33
import { CodeBlock } from './CodeBlock'
44

@@ -34,8 +34,8 @@ export function RestCodeSamples({ slug, xCodeSamples }: Props) {
3434
sampleElements.push(
3535
<CodeBlock
3636
key={sample.lang + index}
37-
codeBlock={sample.sourceHTML}
38-
setHTML={true}
37+
codeBlock={sample.source}
38+
highlight={sample.lang === 'JavaScript' ? 'javascript' : 'curl'}
3939
></CodeBlock>
4040
)
4141
}

components/rest/RestResponse.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export function RestResponse({ responses }: Props) {
1515
<CodeBlock
1616
codeBlock={`Status: ${response.httpStatusCode} ${response.httpStatusMessage}`}
1717
/>
18-
<CodeBlock codeBlock={response.payload} setHTML={true} />
18+
{response.payload ? <CodeBlock codeBlock={response.payload} highlight="json" /> : null}
1919
</div>
2020
)
2121
})}

components/rest/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export interface CodeResponse {
3939

4040
export interface xCodeSample {
4141
lang: string
42-
sourceHTML: string
42+
source: string
4343
}
4444

4545
export interface Preview {

lib/rest/static/decorated/api.github.com.json

Lines changed: 4919 additions & 4919 deletions
Large diffs are not rendered by default.

lib/rest/static/decorated/ghes-3.0.json

Lines changed: 4209 additions & 4209 deletions
Large diffs are not rendered by default.

lib/rest/static/decorated/ghes-3.1.json

Lines changed: 4331 additions & 4331 deletions
Large diffs are not rendered by default.

lib/rest/static/decorated/ghes-3.2.json

Lines changed: 4863 additions & 4863 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)