Skip to content

Commit df549aa

Browse files
committed
Add top level API link to header nav
1 parent 03c02e2 commit df549aa

19 files changed

+122
-39
lines changed

content/docs/reference-dom-elements.md renamed to content/api/dom-elements.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ id: dom-elements
33
title: DOM Elements
44
layout: docs
55
category: Reference
6-
permalink: docs/dom-elements.html
6+
permalink: api/dom-elements.html
77
redirect_from:
8+
- "docs/dom-elements.html"
89
- "docs/tags-and-attributes.html"
910
- "docs/dom-differences.html"
1011
- "docs/special-non-dom-attributes.html"

content/docs/reference-events.md renamed to content/api/events.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
---
22
id: events
33
title: SyntheticEvent
4-
permalink: docs/events.html
4+
permalink: api/events.html
55
layout: docs
66
category: Reference
7+
redirect_from:
8+
- "docs/events.html"
79
---
810

911
This reference guide documents the `SyntheticEvent` wrapper that forms part of React's Event System. See the [Handling Events](/docs/handling-events.html) guide to learn more.

content/docs/reference-glossary.md renamed to content/api/glossary.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ id: glossary
33
title: Glossary of React Terms
44
layout: docs
55
category: Reference
6-
permalink: docs/glossary.html
7-
6+
permalink: api/glossary.html
7+
redirect_from:
8+
- "docs/glossary.html"
89
---
910

1011
## Single-page Application

content/docs/reference-javascript-environment-requirements.md renamed to content/api/javascript-environment-requirements.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ id: javascript-environment-requirements
33
title: JavaScript Environment Requirements
44
layout: docs
55
category: Reference
6-
permalink: docs/javascript-environment-requirements.html
6+
permalink: api/javascript-environment-requirements.html
7+
redirect_from:
8+
- "docs/javascript-environment-requirements.html"
79
---
810

911
React 16 depends on the collection types [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) and [Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set). If you support older browsers and devices which may not yet provide these natively (e.g. IE < 11), consider including a global polyfill in your bundled application, such as [core-js](https://github.com/zloirock/core-js) or [babel-polyfill](https://babeljs.io/docs/usage/polyfill/).

content/api/nav.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
- title: Reference
2+
items:
3+
- id: react-api
4+
title: React
5+
subitems:
6+
- id: react-component
7+
title: React.Component
8+
- id: react-dom
9+
title: ReactDOM
10+
- id: react-dom-server
11+
title: ReactDOMServer
12+
- id: dom-elements
13+
title: DOM Elements
14+
- id: events
15+
title: SyntheticEvent
16+
- id: test-utils
17+
title: Test Utilities
18+
- id: shallow-renderer
19+
title: Shallow Renderer
20+
- id: test-renderer
21+
title: Test Renderer
22+
- id: javascript-environment-requirements
23+
title: JS Environment Requirements
24+
- id: glossary
25+
title: Glossary

content/docs/reference-pure-render-mixin.md renamed to content/api/pure-render-mixin.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ id: pure-render-mixin
33
title: PureRenderMixin
44
layout: docs
55
category: Reference
6-
permalink: docs/pure-render-mixin.html
6+
permalink: api/pure-render-mixin.html
7+
redirect_from:
8+
- "docs/pure-render-mixin.html"
79
---
810

911
> Note

content/docs/reference-react-component.md renamed to content/api/react-component.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ id: react-component
33
title: React.Component
44
layout: docs
55
category: Reference
6-
permalink: docs/react-component.html
6+
permalink: api/react-component.html
77
redirect_from:
8+
- "docs/react-component.html"
89
- "docs/component-api.html"
910
- "docs/component-specs.html"
1011
- "docs/component-specs-ko-KR.html"

content/docs/reference-react-dom-server.md renamed to content/api/react-dom-server.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ id: react-dom-server
33
title: ReactDOMServer
44
layout: docs
55
category: Reference
6-
permalink: docs/react-dom-server.html
6+
permalink: api/react-dom-server.html
7+
redirect_from:
8+
- "docs/react-dom-server.html"
79
---
810

911
The `ReactDOMServer` object enables you to render components to static markup. Typically, it's used on a Node server:

content/docs/reference-react-dom.md renamed to content/api/react-dom.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ id: react-dom
33
title: ReactDOM
44
layout: docs
55
category: Reference
6-
permalink: docs/react-dom.html
6+
permalink: api/react-dom.html
7+
redirect_from:
8+
- "docs/react-dom.html"
79
---
810

911
If you load React from a `<script>` tag, these top-level APIs are available on the `ReactDOM` global. If you use ES6 with npm, you can write `import ReactDOM from 'react-dom'`. If you use ES5 with npm, you can write `var ReactDOM = require('react-dom')`.

content/docs/reference-react.md renamed to content/api/react.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ id: react-api
33
title: React Top-Level API
44
layout: docs
55
category: Reference
6-
permalink: docs/react-api.html
6+
permalink: api/react-api.html
77
redirect_from:
8+
- "docs/react-api.html"
89
- "docs/reference.html"
910
- "docs/clone-with-props.html"
1011
- "docs/top-level-api.html"

content/docs/addons-shallow-renderer.md renamed to content/api/shallow-renderer.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
---
22
id: shallow-renderer
33
title: Shallow Renderer
4-
permalink: docs/shallow-renderer.html
4+
permalink: api/shallow-renderer.html
55
layout: docs
66
category: Reference
7+
redirect_from:
8+
- "docs/shallow-renderer.html"
79
---
810

911
**Importing**

content/docs/reference-test-renderer.md renamed to content/api/test-renderer.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
---
22
id: test-renderer
33
title: Test Renderer
4-
permalink: docs/test-renderer.html
4+
permalink: api/test-renderer.html
55
layout: docs
66
category: Reference
7+
redirect_from:
8+
- "docs/test-renderer.html"
79
---
810

911
**Importing**

content/docs/addons-test-utils.md renamed to content/api/test-utils.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
---
22
id: test-utils
33
title: Test Utilities
4-
permalink: docs/test-utils.html
4+
permalink: api/test-utils.html
55
layout: docs
66
category: Reference
7+
redirect_from:
8+
- "docs/test-utils.html"
79
---
810

911
**Importing**

content/docs/nav.yml

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -58,31 +58,6 @@
5858
title: Integrating with Other Libraries
5959
- id: accessibility
6060
title: Accessibility
61-
- title: Reference
62-
items:
63-
- id: react-api
64-
title: React
65-
subitems:
66-
- id: react-component
67-
title: React.Component
68-
- id: react-dom
69-
title: ReactDOM
70-
- id: react-dom-server
71-
title: ReactDOMServer
72-
- id: dom-elements
73-
title: DOM Elements
74-
- id: events
75-
title: SyntheticEvent
76-
- id: test-utils
77-
title: Test Utilities
78-
- id: shallow-renderer
79-
title: Shallow Renderer
80-
- id: test-renderer
81-
title: Test Renderer
82-
- id: javascript-environment-requirements
83-
title: JS Environment Requirements
84-
- id: glossary
85-
title: Glossary
8661
- title: Contributing
8762
items:
8863
- id: how-to-contribute

gatsby-node.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ exports.createPages = async ({graphql, boundActionCreators}) => {
3131
const blogTemplate = resolve('./src/templates/blog.js');
3232
const communityTemplate = resolve('./src/templates/community.js');
3333
const docsTemplate = resolve('./src/templates/docs.js');
34+
const apiTemplate = resolve('./src/templates/api.js');
3435
const tutorialTemplate = resolve('./src/templates/tutorial.js');
3536
const homeTemplate = resolve('./src/templates/home.js');
3637

@@ -77,6 +78,7 @@ exports.createPages = async ({graphql, boundActionCreators}) => {
7778
slug.includes('community/') ||
7879
slug.includes('contributing/') ||
7980
slug.includes('docs/') ||
81+
slug.includes('api/') ||
8082
slug.includes('tutorial/') ||
8183
slug.includes('warnings/')
8284
) {
@@ -85,6 +87,8 @@ exports.createPages = async ({graphql, boundActionCreators}) => {
8587
template = blogTemplate;
8688
} else if (slug.includes('community/')) {
8789
template = communityTemplate;
90+
} else if (slug.includes('api/')) {
91+
template = apiTemplate;
8892
} else if (
8993
slug.includes('contributing/') ||
9094
slug.includes('docs/') ||

src/components/LayoutHeader/Header.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ const Header = ({location}) => (
118118
title="Docs"
119119
to="/docs/hello-world.html"
120120
/>
121+
<HeaderLink
122+
isActive={location.pathname.includes('/api/')}
123+
title="API"
124+
to="/api/react-api.html"
125+
/>
121126
<HeaderLink
122127
isActive={location.pathname.includes('/tutorial/')}
123128
title="Tutorial"

src/layouts/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class Template extends Component {
4242
let layoutHasSidebar = false;
4343
if (
4444
location.pathname.match(
45-
/^\/(docs|tutorial|community|blog|contributing|warnings)/,
45+
/^\/(docs|api|tutorial|community|blog|contributing|warnings)/,
4646
)
4747
) {
4848
layoutHasSidebar = true;

src/templates/api.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* Copyright (c) 2013-present, Facebook, Inc.
3+
*
4+
* @emails react-core
5+
*/
6+
7+
'use strict';
8+
9+
import MarkdownPage from 'components/MarkdownPage';
10+
import PropTypes from 'prop-types';
11+
import React from 'react';
12+
import {createLinkDocs} from 'utils/createLink';
13+
import {sectionListAPI} from 'utils/sectionList';
14+
15+
const Api = ({data, location}) => (
16+
<MarkdownPage
17+
createLink={createLinkDocs}
18+
location={location}
19+
markdownRemark={data.markdownRemark}
20+
sectionList={sectionListAPI}
21+
titlePostfix=" - React"
22+
/>
23+
);
24+
25+
Api.propTypes = {
26+
data: PropTypes.object.isRequired,
27+
};
28+
29+
// eslint-disable-next-line no-undef
30+
export const pageQuery = graphql`
31+
query TemplateApiMarkdown($slug: String!) {
32+
markdownRemark(fields: {slug: {eq: $slug}}) {
33+
html
34+
frontmatter {
35+
title
36+
next
37+
prev
38+
}
39+
fields {
40+
path
41+
slug
42+
}
43+
}
44+
}
45+
`;
46+
47+
export default Api;

src/utils/sectionList.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import navCommunity from '../../content/community/nav.yml';
1010
import navDocs from '../../content/docs/nav.yml';
1111
import navTutorial from '../../content/tutorial/nav.yml';
12+
import navAPI from '../../content/api/nav.yml';
1213

1314
const sectionListDocs = navDocs.map(item => ({
1415
...item,
@@ -20,8 +21,14 @@ const sectionListCommunity = navCommunity.map(item => ({
2021
directory: 'community',
2122
}));
2223

24+
const sectionListAPI = navAPI.map(item => ({
25+
...item,
26+
directory: 'api',
27+
}));
28+
2329
export {
2430
sectionListCommunity,
2531
sectionListDocs,
32+
sectionListAPI,
2633
navTutorial as sectionListTutorial,
2734
};

0 commit comments

Comments
 (0)