Skip to content

Commit 2b09c53

Browse files
authored
Merge pull request reactjs#262 from bvaughn/gatsby-remark-code-repls
Migrate to new Gatbsy plug-in: gatsby-remark-code-repls
2 parents c2362f3 + 04ad4fd commit 2b09c53

File tree

14 files changed

+50
-184
lines changed

14 files changed

+50
-184
lines changed

content/docs/hello-world.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ The next few sections will gradually introduce you to using React. We will exami
3131

3232
React is a JavaScript library, and so it assumes you have a basic understanding of the JavaScript language. If you don't feel very confident, we recommend [refreshing your JavaScript knowledge](https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re-introduction_to_JavaScript) so you can follow along more easily.
3333

34-
We also use some of the ES6 syntax in the examples. We try to use it sparingly because it's still relatively new, but we encourage you to get familiar with [arrow functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions), [classes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes), [template literals](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Template_literals), [`let`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let), and [`const`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const) statements. You can use the [Babel REPL](babel-repl://es5-syntax-example) to check what ES6 code compiles to.
34+
We also use some of the ES6 syntax in the examples. We try to use it sparingly because it's still relatively new, but we encourage you to get familiar with [arrow functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions), [classes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes), [template literals](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Template_literals), [`let`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let), and [`const`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const) statements. You can use the [Babel REPL](babel://es5-syntax-example) to check what ES6 code compiles to.

content/docs/jsx-in-depth.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ React.createElement(
4747
)
4848
```
4949

50-
If you want to test out how some specific JSX is converted into JavaScript, you can try out [the online Babel compiler](babel-repl://jsx-simple-example).
50+
If you want to test out how some specific JSX is converted into JavaScript, you can try out [the online Babel compiler](babel://jsx-simple-example).
5151

5252
## Specifying The React Element Type
5353

content/docs/react-without-jsx.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ ReactDOM.render(
3838
);
3939
```
4040

41-
If you're curious to see more examples of how JSX is converted to JavaScript, you can try out [the online Babel compiler](babel-repl://jsx-simple-example).
41+
If you're curious to see more examples of how JSX is converted to JavaScript, you can try out [the online Babel compiler](babel://jsx-simple-example).
4242

4343
The component can either be provided as a string, or as a subclass of `React.Component`, or a plain function for stateless components.
4444

content/home/examples/a-simple-component.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ order: 0
55

66
React components implement a `render()` method that takes input data and returns what to display. This example uses an XML-like syntax called JSX. Input data that is passed into the component can be accessed by `render()` via `this.props`.
77

8-
**JSX is optional and not required to use React.** Try the [Babel REPL](babel-repl://es5-syntax-example) to see the raw JavaScript code produced by the JSX compilation step.
8+
**JSX is optional and not required to use React.** Try the [Babel REPL](babel://es5-syntax-example) to see the raw JavaScript code produced by the JSX compilation step.

content/tutorial/tutorial.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Once you get a little familiar with the game, feel free to close that tab, as we
2828

2929
We'll assume some familiarity with HTML and JavaScript, but you should be able to follow along even if you haven't used them before.
3030

31-
If you need a refresher on JavaScript, we recommend reading [this guide](https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re-introduction_to_JavaScript). Note that we're also using some features from ES6, a recent version of JavaScript. In this tutorial, we're using [arrow functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions), [classes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes), [`let`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let), and [`const`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const) statements. You can use the [Babel REPL](babel-repl://es5-syntax-example) to check what ES6 code compiles to.
31+
If you need a refresher on JavaScript, we recommend reading [this guide](https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re-introduction_to_JavaScript). Note that we're also using some features from ES6, a recent version of JavaScript. In this tutorial, we're using [arrow functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions), [classes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes), [`let`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let), and [`const`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const) statements. You can use the [Babel REPL](babel://es5-syntax-example) to check what ES6 code compiles to.
3232

3333
### How to Follow Along
3434

@@ -129,7 +129,7 @@ return React.createElement('div', {className: 'shopping-list'},
129129
);
130130
```
131131

132-
[See full expanded version.](babel-repl://tutorial-expanded-version)
132+
[See full expanded version.](babel://tutorial-expanded-version)
133133

134134
If you're curious, `createElement()` is described in more detail in the [API reference](/docs/react-api.html#createelement), but we won't be using it directly in this tutorial. Instead, we will keep using JSX.
135135

gatsby-config.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
'use strict';
88

9+
const {join} = require('path');
10+
911
module.exports = {
1012
siteMetadata: {
1113
title: 'React: A JavaScript library for building user interfaces',
@@ -57,15 +59,16 @@ module.exports = {
5759
},
5860
'gatsby-remark-autolink-headers',
5961
{
60-
resolve: 'gatsby-remark-codepen-examples',
61-
options: {
62-
directory: 'examples',
63-
},
64-
},
65-
{
66-
resolve: 'gatsby-remark-babel-repl-link',
62+
resolve: 'gatsby-remark-code-repls',
6763
options: {
68-
directory: 'examples',
64+
defaultText: 'Try it on CodePen',
65+
directory: `${__dirname}/examples/`,
66+
externals: [
67+
`//unpkg.com/react/umd/react.development.js`,
68+
`//unpkg.com/react-dom/umd/react-dom.development.js`,
69+
],
70+
redirectTemplate: `${__dirname}/src/templates/codepen-example.js`,
71+
target: '_blank',
6972
},
7073
},
7174
'gatsby-remark-use-jsx',

gatsby-node.js

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -167,24 +167,6 @@ exports.createPages = async ({graphql, boundActionCreators}) => {
167167
redirectInBrowser: true,
168168
toPath: newestBlogNode.fields.slug,
169169
});
170-
171-
// Create Codepen redirects.
172-
// These use the Codepen prefill API to JIT-create Pens.
173-
// https://blog.codepen.io/documentation/api/prefill/
174-
const files = await recursiveReaddir('./examples');
175-
files.forEach(file => {
176-
const slug = file.substring(0, file.length - 3); // Trim extension
177-
const code = readFileSync(file, 'utf8');
178-
179-
createPage({
180-
path: slug,
181-
component: resolve('./src/templates/codepen-example.js'),
182-
context: {
183-
code,
184-
slug,
185-
},
186-
});
187-
});
188170
};
189171

190172
// Parse date information out of blog post filename.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"gatsby-plugin-sharp": "^1.6.2",
4141
"gatsby-plugin-twitter": "^1.0.10",
4242
"gatsby-remark-autolink-headers": "^1.4.4",
43+
"gatsby-remark-code-repls": "^1.0.2",
4344
"gatsby-remark-copy-linked-files": "^1.5.2",
4445
"gatsby-remark-images": "^1.5.11",
4546
"gatsby-remark-prismjs": "^1.2.1",

plugins/gatsby-remark-babel-repl-link/index.js

Lines changed: 0 additions & 68 deletions
This file was deleted.

plugins/gatsby-remark-babel-repl-link/package.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)