Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 04d4f13

Browse files
authored
feat(api): add link to json docs (#2911)
1 parent d51f791 commit 04d4f13

File tree

14 files changed

+113
-9
lines changed

14 files changed

+113
-9
lines changed

apiUrls.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ module.exports = {
77
nodeReleaseData: 'https://nodejs.org/dist/index.json',
88
nodeBannersData:
99
'https://raw.githubusercontent.com/nodejs/nodejs.org/main/locale/en/site.json',
10+
jsonLink: (fileName, version) =>
11+
`https://nodejs.org/docs/latest-${version}.x/api/${fileName}.json`,
1012
};
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
.json {
2+
display: flex;
3+
flex-wrap: wrap;
4+
5+
a {
6+
color: var(--color-text-secondary);
7+
font-family: var(--sans-serif);
8+
font-size: 1.4rem;
9+
font-weight: var(--font-weight-regular);
10+
margin-left: 0;
11+
text-decoration: none !important;
12+
text-transform: uppercase;
13+
vertical-align: middle;
14+
15+
span {
16+
font-weight: var(--font-weight-regular);
17+
vertical-align: middle;
18+
}
19+
20+
&:hover {
21+
color: var(--brand-light);
22+
}
23+
24+
svg {
25+
margin-left: 0.5rem;
26+
vertical-align: middle;
27+
}
28+
}
29+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React from 'react';
2+
import { FormattedMessage } from 'react-intl';
3+
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
4+
import { faRobot } from '@fortawesome/free-solid-svg-icons';
5+
import { jsonLink } from '../../../../../apiUrls';
6+
import styles from './index.module.scss';
7+
8+
interface Props {
9+
fileName: string;
10+
version: string;
11+
}
12+
13+
const JsonLink = ({ fileName, version }: Props): JSX.Element | null => (
14+
<div className={styles.json}>
15+
<a href={jsonLink(fileName, version)}>
16+
<FormattedMessage id="components.jsonLink.title" tagName="span" />
17+
<FontAwesomeIcon icon={faRobot} />
18+
</a>
19+
</div>
20+
);
21+
22+
export default JsonLink;

src/components/ApiComponents/Components/__tests__/__snapshots__/index.test.tsx.snap

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,34 @@ exports[`ApiComponents Components renders H5 component correctly 1`] = `
3131
/>
3232
</div>
3333
`;
34+
35+
exports[`ApiComponents Components renders JsonLink component correctly 1`] = `
36+
<div>
37+
<div
38+
class="json"
39+
>
40+
<a
41+
href="https://nodejs.org/docs/latest-v18.x/api/cli.json"
42+
>
43+
<span>
44+
View as JSON
45+
</span>
46+
<svg
47+
aria-hidden="true"
48+
class="svg-inline--fa fa-robot "
49+
data-icon="robot"
50+
data-prefix="fas"
51+
focusable="false"
52+
role="img"
53+
viewBox="0 0 640 512"
54+
xmlns="http://www.w3.org/2000/svg"
55+
>
56+
<path
57+
d="M320 0c17.7 0 32 14.3 32 32V96H480c35.3 0 64 28.7 64 64V448c0 35.3-28.7 64-64 64H160c-35.3 0-64-28.7-64-64V160c0-35.3 28.7-64 64-64H288V32c0-17.7 14.3-32 32-32zM208 384c-8.8 0-16 7.2-16 16s7.2 16 16 16h32c8.8 0 16-7.2 16-16s-7.2-16-16-16H208zm96 0c-8.8 0-16 7.2-16 16s7.2 16 16 16h32c8.8 0 16-7.2 16-16s-7.2-16-16-16H304zm96 0c-8.8 0-16 7.2-16 16s7.2 16 16 16h32c8.8 0 16-7.2 16-16s-7.2-16-16-16H400zM264 256c0-22.1-17.9-40-40-40s-40 17.9-40 40s17.9 40 40 40s40-17.9 40-40zm152 40c22.1 0 40-17.9 40-40s-17.9-40-40-40s-40 17.9-40 40s17.9 40 40 40zM48 224H64V416H48c-26.5 0-48-21.5-48-48V272c0-26.5 21.5-48 48-48zm544 0c26.5 0 48 21.5 48 48v96c0 26.5-21.5 48-48 48H576V224h16z"
58+
fill="currentColor"
59+
/>
60+
</svg>
61+
</a>
62+
</div>
63+
</div>
64+
`;

src/components/ApiComponents/Components/__tests__/index.test.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import { render } from '@testing-library/react';
3-
import { ApiLink, H5, H4, H3 } from '..';
3+
import { ApiLink, H5, H4, H3, JsonLink } from '..';
44

55
describe('ApiComponents Components', (): void => {
66
it('renders ApiLink component correctly', () => {
@@ -28,4 +28,9 @@ describe('ApiComponents Components', (): void => {
2828
const { container } = render(<H3 id={id} />);
2929
expect(container).toMatchSnapshot();
3030
});
31+
32+
it('renders JsonLink component correctly', () => {
33+
const { container } = render(<JsonLink fileName="cli" version="v18" />);
34+
expect(container).toMatchSnapshot();
35+
});
3136
});

src/components/ApiComponents/Components/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ export { default as SourceLink } from './SourceLink';
44
export { default as Changes } from './Changes';
55
export { default as VersionSelector } from './VersionSelector';
66
export { default as Span } from './Span';
7+
export { default as JsonLink } from './JsonLink';
78
export * from './ApiHeading';

src/i18n/locales/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"components.downloadToggle.lts": "LTS",
2222
"components.downloadToggle.recommendation": "{selected, select, LTS {Recommended for most users}other {With the latest features}}",
2323
"components.editLink.title": "Edit this page on GitHub",
24+
"components.jsonLink.title": "View as JSON",
2425
"components.footer.links.trademark": "Trademark Policy",
2526
"components.footer.links.privacy": "Privacy Policy",
2627
"components.footer.links.codeOfConduct": "Code of Conduct",

src/i18n/locales/es.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"components.downloadToggle.lts": "LTS",
2222
"components.downloadToggle.recommendation": "{selected, select, LTS {Recommended for most users}other {With the latest features}}",
2323
"components.editLink.title": "Edit this page on GitHub",
24+
"components.jsonLink.title": "View as JSON",
2425
"components.footer.links.trademark": "Trademark Policy",
2526
"components.footer.links.privacy": "Privacy Policy",
2627
"components.footer.links.codeOfConduct": "Code of Conduct",

src/i18n/locales/fr.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"components.downloadToggle.lts": "LTS",
2222
"components.downloadToggle.recommendation": "{selected, select, LTS {Recommended for most users}other {With the latest features}}",
2323
"components.editLink.title": "Modifier cette page sur GitHub",
24+
"components.jsonLink.title": "Afficher en JSON",
2425
"components.footer.links.trademark": "Politique en matière de marques",
2526
"components.footer.links.privacy": "Politique de confidentialité",
2627
"components.footer.links.codeOfConduct": "Code de conduite",

src/i18n/locales/zh-cn.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"components.downloadToggle.lts": "LTS",
2222
"components.downloadToggle.recommendation": "{selected, select, LTS {Recommended for most users}other {With the latest features}}",
2323
"components.editLink.title": "在 GitHub 上编辑此页面",
24+
"components.jsonLink.title": "View as JSON",
2425
"components.footer.links.trademark": "商标政策",
2526
"components.footer.links.privacy": "隐私政策",
2627
"components.footer.links.codeOfConduct": "行为准则",

0 commit comments

Comments
 (0)