Skip to content

Migrate to new Gatbsy plug-in: gatsby-remark-code-repls #262

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion content/docs/hello-world.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ The next few sections will gradually introduce you to using React. We will exami

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.

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.
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.
2 changes: 1 addition & 1 deletion content/docs/jsx-in-depth.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ React.createElement(
)
```

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).
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).

## Specifying The React Element Type

Expand Down
2 changes: 1 addition & 1 deletion content/docs/react-without-jsx.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ ReactDOM.render(
);
```

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).
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).

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

Expand Down
2 changes: 1 addition & 1 deletion content/home/examples/a-simple-component.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ order: 0

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`.

**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.
**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.
4 changes: 2 additions & 2 deletions content/tutorial/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Once you get a little familiar with the game, feel free to close that tab, as we

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.

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

### How to Follow Along

Expand Down Expand Up @@ -129,7 +129,7 @@ return React.createElement('div', {className: 'shopping-list'},
);
```

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

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.

Expand Down
19 changes: 11 additions & 8 deletions gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

'use strict';

const {join} = require('path');

module.exports = {
siteMetadata: {
title: 'React: A JavaScript library for building user interfaces',
Expand Down Expand Up @@ -57,15 +59,16 @@ module.exports = {
},
'gatsby-remark-autolink-headers',
{
resolve: 'gatsby-remark-codepen-examples',
options: {
directory: 'examples',
},
},
{
resolve: 'gatsby-remark-babel-repl-link',
resolve: 'gatsby-remark-code-repls',
options: {
directory: 'examples',
defaultText: 'Try it on CodePen',
directory: `${__dirname}/examples/`,
externals: [
`//unpkg.com/react/umd/react.development.js`,
`//unpkg.com/react-dom/umd/react-dom.development.js`,
],
redirectTemplate: `${__dirname}/src/templates/codepen-example.js`,
target: '_blank',
},
},
'gatsby-remark-use-jsx',
Expand Down
18 changes: 0 additions & 18 deletions gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,24 +167,6 @@ exports.createPages = async ({graphql, boundActionCreators}) => {
redirectInBrowser: true,
toPath: newestBlogNode.fields.slug,
});

// Create Codepen redirects.
// These use the Codepen prefill API to JIT-create Pens.
// https://blog.codepen.io/documentation/api/prefill/
const files = await recursiveReaddir('./examples');
files.forEach(file => {
const slug = file.substring(0, file.length - 3); // Trim extension
const code = readFileSync(file, 'utf8');

createPage({
path: slug,
component: resolve('./src/templates/codepen-example.js'),
context: {
code,
slug,
},
});
});
};

// Parse date information out of blog post filename.
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"gatsby-plugin-sharp": "^1.6.2",
"gatsby-plugin-twitter": "^1.0.10",
"gatsby-remark-autolink-headers": "^1.4.4",
"gatsby-remark-code-repls": "^1.0.2",
"gatsby-remark-copy-linked-files": "^1.5.2",
"gatsby-remark-images": "^1.5.11",
"gatsby-remark-prismjs": "^1.2.1",
Expand Down
68 changes: 0 additions & 68 deletions plugins/gatsby-remark-babel-repl-link/index.js

This file was deleted.

4 changes: 0 additions & 4 deletions plugins/gatsby-remark-babel-repl-link/package.json

This file was deleted.

64 changes: 0 additions & 64 deletions plugins/gatsby-remark-codepen-examples/index.js

This file was deleted.

4 changes: 0 additions & 4 deletions plugins/gatsby-remark-codepen-examples/package.json

This file was deleted.

14 changes: 2 additions & 12 deletions src/templates/codepen-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,7 @@ class CodepenExample extends Component {
}

render() {
// Codepen configuration.
// https://blog.codepen.io/documentation/api/prefill/
const payload = JSON.stringify({
editors: '0010',
html: '<div id="root"></div>',
js: this.props.pathContext.code,
js_external: EXTERNALS.join(';'),
js_pre_processor: 'babel',
layout: 'left',
title: 'reactjs.org example',
});
const {action, payload} = this.props.pathContext;

return (
<Container>
Expand All @@ -54,7 +44,7 @@ class CodepenExample extends Component {
ref={form => {
this.codepenForm = form;
}}
action="https://codepen.io/pen/define"
action={action}
method="POST">
<input type="hidden" name="data" value={payload} />

Expand Down
30 changes: 30 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4052,6 +4052,15 @@ gatsby-remark-autolink-headers@^1.4.4:
mdast-util-to-string "^1.0.2"
unist-util-visit "^1.1.1"

gatsby-remark-code-repls@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/gatsby-remark-code-repls/-/gatsby-remark-code-repls-1.0.2.tgz#2a6df584d4c60388aa4c1140d9693c40b3d8d561"
dependencies:
babel-runtime "^6.26.0"
lz-string "^1.4.4"
recursive-readdir-synchronous "^0.0.3"
unist-util-map "^1.0.3"

gatsby-remark-copy-linked-files@^1.5.2:
version "1.5.18"
resolved "https://registry.yarnpkg.com/gatsby-remark-copy-linked-files/-/gatsby-remark-copy-linked-files-1.5.18.tgz#ff7932922fd1b1696695bb174f8ecc743097d9a0"
Expand Down Expand Up @@ -6174,6 +6183,10 @@ lpad-align@^1.0.1:
longest "^1.0.0"
meow "^3.3.0"

lru-cache@2:
version "2.7.3"
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-2.7.3.tgz#6d4524e8b955f95d4f5b58851ce21dd72fb4e952"

lru-cache@^4.0.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-4.1.1.tgz#622e32e82488b49279114a4f9ecf45e7cd6bba55"
Expand Down Expand Up @@ -6485,6 +6498,13 @@ minimalistic-crypto-utils@^1.0.0, minimalistic-crypto-utils@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/minimalistic-crypto-utils/-/minimalistic-crypto-utils-1.0.1.tgz#f6c00c1c0b082246e5c4d99dfb8c7c083b2b582a"

minimatch@0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-0.3.0.tgz#275d8edaac4f1bb3326472089e7949c8394699dd"
dependencies:
lru-cache "2"
sigmund "~1.0.0"

"minimatch@2 || 3", minimatch@^3.0.0, minimatch@^3.0.2, minimatch@^3.0.3, minimatch@^3.0.4:
version "3.0.4"
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083"
Expand Down Expand Up @@ -8257,6 +8277,12 @@ rechoir@^0.6.2:
dependencies:
resolve "^1.1.6"

recursive-readdir-synchronous@^0.0.3:
version "0.0.3"
resolved "https://registry.yarnpkg.com/recursive-readdir-synchronous/-/recursive-readdir-synchronous-0.0.3.tgz#d5e5a096ad56cf9666241c22a30b4f338bb7ed88"
dependencies:
minimatch "0.3.0"

recursive-readdir@2.2.1, recursive-readdir@^2.2.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/recursive-readdir/-/recursive-readdir-2.2.1.tgz#90ef231d0778c5ce093c9a48d74e5c5422d13a99"
Expand Down Expand Up @@ -9096,6 +9122,10 @@ sift@^3.2.6:
version "3.3.12"
resolved "https://registry.yarnpkg.com/sift/-/sift-3.3.12.tgz#4f5cdf16af3db32afa04ab25297b0e20ad98294a"

sigmund@~1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/sigmund/-/sigmund-1.0.1.tgz#3ff21f198cad2175f9f3b781853fd94d0d19b590"

signal-exit@^3.0.0, signal-exit@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"
Expand Down