mirror of
https://github.com/reactjs/react.dev.git
synced 2026-02-22 03:42:14 +00:00
Moved home page example code to /content/home
Now examples are trasnformed to GraphQL during build and assembled by the index template. This makes them easier to edit and tie in with their associated markdown description.
This commit is contained in:
28
plugins/gatsby-transformer-home-example-code/gatsby-node.js
Normal file
28
plugins/gatsby-transformer-home-example-code/gatsby-node.js
Normal file
@@ -0,0 +1,28 @@
|
||||
const {readdirSync, readFileSync} = require('fs');
|
||||
const {join, resolve} = require('path');
|
||||
|
||||
// Store code snippets in GraphQL for the home page examples.
|
||||
// Snippets will be matched with markdown templates of the same name.
|
||||
exports.sourceNodes = ({graphql, boundActionCreators}) => {
|
||||
const {createNode} = boundActionCreators;
|
||||
|
||||
const path = resolve(__dirname, '../../content/home/examples');
|
||||
const files = readdirSync(path);
|
||||
|
||||
files.forEach(file => {
|
||||
if (file.match(/\.js$/)) {
|
||||
const code = readFileSync(join(path, file), 'utf8');
|
||||
const id = file.replace(/\.js$/, '');
|
||||
|
||||
createNode({
|
||||
id,
|
||||
children: [],
|
||||
parent: 'EXAMPLES',
|
||||
internal: {
|
||||
type: 'ExampleCode',
|
||||
contentDigest: JSON.stringify(code),
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"name": "gatsby-transformer-home-example-code",
|
||||
"version": "0.0.1"
|
||||
}
|
||||
Reference in New Issue
Block a user