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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+2-2
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

+11-8
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

-18
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

+1
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

-68
This file was deleted.

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

-4
This file was deleted.

plugins/gatsby-remark-codepen-examples/index.js

-64
This file was deleted.

plugins/gatsby-remark-codepen-examples/package.json

-4
This file was deleted.

src/templates/codepen-example.js

+2-12
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,7 @@ class CodepenExample extends Component {
3434
}
3535

3636
render() {
37-
// Codepen configuration.
38-
// https://blog.codepen.io/documentation/api/prefill/
39-
const payload = JSON.stringify({
40-
editors: '0010',
41-
html: '<div id="root"></div>',
42-
js: this.props.pathContext.code,
43-
js_external: EXTERNALS.join(';'),
44-
js_pre_processor: 'babel',
45-
layout: 'left',
46-
title: 'reactjs.org example',
47-
});
37+
const {action, payload} = this.props.pathContext;
4838

4939
return (
5040
<Container>
@@ -54,7 +44,7 @@ class CodepenExample extends Component {
5444
ref={form => {
5545
this.codepenForm = form;
5646
}}
57-
action="https://codepen.io/pen/define"
47+
action={action}
5848
method="POST">
5949
<input type="hidden" name="data" value={payload} />
6050

yarn.lock

+30
Original file line numberDiff line numberDiff line change
@@ -4052,6 +4052,15 @@ gatsby-remark-autolink-headers@^1.4.4:
40524052
mdast-util-to-string "^1.0.2"
40534053
unist-util-visit "^1.1.1"
40544054

4055+
gatsby-remark-code-repls@^1.0.2:
4056+
version "1.0.2"
4057+
resolved "https://registry.yarnpkg.com/gatsby-remark-code-repls/-/gatsby-remark-code-repls-1.0.2.tgz#2a6df584d4c60388aa4c1140d9693c40b3d8d561"
4058+
dependencies:
4059+
babel-runtime "^6.26.0"
4060+
lz-string "^1.4.4"
4061+
recursive-readdir-synchronous "^0.0.3"
4062+
unist-util-map "^1.0.3"
4063+
40554064
gatsby-remark-copy-linked-files@^1.5.2:
40564065
version "1.5.18"
40574066
resolved "https://registry.yarnpkg.com/gatsby-remark-copy-linked-files/-/gatsby-remark-copy-linked-files-1.5.18.tgz#ff7932922fd1b1696695bb174f8ecc743097d9a0"
@@ -6174,6 +6183,10 @@ lpad-align@^1.0.1:
61746183
longest "^1.0.0"
61756184
meow "^3.3.0"
61766185

6186+
lru-cache@2:
6187+
version "2.7.3"
6188+
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-2.7.3.tgz#6d4524e8b955f95d4f5b58851ce21dd72fb4e952"
6189+
61776190
lru-cache@^4.0.1:
61786191
version "4.1.1"
61796192
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-4.1.1.tgz#622e32e82488b49279114a4f9ecf45e7cd6bba55"
@@ -6485,6 +6498,13 @@ minimalistic-crypto-utils@^1.0.0, minimalistic-crypto-utils@^1.0.1:
64856498
version "1.0.1"
64866499
resolved "https://registry.yarnpkg.com/minimalistic-crypto-utils/-/minimalistic-crypto-utils-1.0.1.tgz#f6c00c1c0b082246e5c4d99dfb8c7c083b2b582a"
64876500

6501+
6502+
version "0.3.0"
6503+
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-0.3.0.tgz#275d8edaac4f1bb3326472089e7949c8394699dd"
6504+
dependencies:
6505+
lru-cache "2"
6506+
sigmund "~1.0.0"
6507+
64886508
"minimatch@2 || 3", minimatch@^3.0.0, minimatch@^3.0.2, minimatch@^3.0.3, minimatch@^3.0.4:
64896509
version "3.0.4"
64906510
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083"
@@ -8257,6 +8277,12 @@ rechoir@^0.6.2:
82578277
dependencies:
82588278
resolve "^1.1.6"
82598279

8280+
recursive-readdir-synchronous@^0.0.3:
8281+
version "0.0.3"
8282+
resolved "https://registry.yarnpkg.com/recursive-readdir-synchronous/-/recursive-readdir-synchronous-0.0.3.tgz#d5e5a096ad56cf9666241c22a30b4f338bb7ed88"
8283+
dependencies:
8284+
minimatch "0.3.0"
8285+
82608286
[email protected], recursive-readdir@^2.2.1:
82618287
version "2.2.1"
82628288
resolved "https://registry.yarnpkg.com/recursive-readdir/-/recursive-readdir-2.2.1.tgz#90ef231d0778c5ce093c9a48d74e5c5422d13a99"
@@ -9096,6 +9122,10 @@ sift@^3.2.6:
90969122
version "3.3.12"
90979123
resolved "https://registry.yarnpkg.com/sift/-/sift-3.3.12.tgz#4f5cdf16af3db32afa04ab25297b0e20ad98294a"
90989124

9125+
sigmund@~1.0.0:
9126+
version "1.0.1"
9127+
resolved "https://registry.yarnpkg.com/sigmund/-/sigmund-1.0.1.tgz#3ff21f198cad2175f9f3b781853fd94d0d19b590"
9128+
90999129
signal-exit@^3.0.0, signal-exit@^3.0.2:
91009130
version "3.0.2"
91019131
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"

0 commit comments

Comments
 (0)