Skip to content
This repository has been archived by the owner on Sep 17, 2018. It is now read-only.

Commit

Permalink
Add examples folder
Browse files Browse the repository at this point in the history
  • Loading branch information
Duc Nguyen committed May 22, 2018
1 parent dee0c3f commit 09bd74c
Show file tree
Hide file tree
Showing 26 changed files with 22,291 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .npmignore
@@ -0,0 +1,3 @@
examples
node_modules
yarn-error.log
5 changes: 5 additions & 0 deletions README.md
Expand Up @@ -21,3 +21,8 @@ In your gatsby-config.js
## Usage

Check mdx document for syntax and examples: https://github.com/mdx-js/mdx#mdx-syntax


##Example

Check `examples` folder for working examples
8 changes: 8 additions & 0 deletions examples/basic/.gitignore
@@ -0,0 +1,8 @@
# Project dependencies
.cache
node_modules
yarn-error.log

# Build directory
/public
.DS_Store
5 changes: 5 additions & 0 deletions examples/basic/.prettierrc
@@ -0,0 +1,5 @@
{
"semi": false,
"singleQuote": true,
"trailingComma": "es5"
}
26 changes: 26 additions & 0 deletions examples/basic/GATSBY_README.1.md
@@ -0,0 +1,26 @@
# gatsby-starter-default
The default Gatsby starter.

For an overview of the project structure please refer to the [Gatsby documentation - Building with Components](https://www.gatsbyjs.org/docs/building-with-components/).

## Install

Make sure that you have the Gatsby CLI program installed:
```sh
npm install --global gatsby-cli
```

And run from your CLI:
```sh
gatsby new gatsby-example-site
```

Then you can run it by:
```sh
cd gatsby-example-site
npm run develop
```

## Deploy

[![Deploy to Netlify](https://www.netlify.com/img/deploy/button.svg)](https://app.netlify.com/start/deploy?repository=https://github.com/gatsbyjs/gatsby-starter-default)
22 changes: 22 additions & 0 deletions examples/basic/LICENSE
@@ -0,0 +1,22 @@
The MIT License (MIT)

Copyright (c) 2015 gatsbyjs

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

82 changes: 82 additions & 0 deletions examples/basic/README.md
@@ -0,0 +1,82 @@
# Basic example

To create MDX pages add the `gatsby-source-filesystem` plugin pointed at the `pages/` directory.

`gatsby-config.js`

```js
module.exports = {
plugins: [
'gatsby-plugin-mdx',
{
resolve: 'gatsby-source-filesystem',
options: {
name: 'pages',
path: `${__dirname}/src/pages/`,
},
},
],
}
```

Next, query all markdown files and, using the `createPage` method, create corresponding pages for each of them.

`gatsby-node.js`

```js
exports.createPages = ({ graphql, boundActionCreators }) => {
const { createPage } = boundActionCreators

return new Promise((resolve, reject) => {
graphql(`
{
allFile(filter: { extension: { eq: "md" } }) {
edges {
node {
absolutePath
relativeDirectory
name
}
}
}
}
`)
.then(result => {
if (result.errors) {
return reject(result.errors)
}

// Create markdown pages.
result.data.allFile.edges.forEach(
({ node: { absolutePath, relativeDirectory, name } }) => {
createPage({
path: `${relativeDirectory}/${name}`,
component: absolutePath,
})
}
)
})
.then(resolve)
})
}
```

Create your markdown pages 🎉

`src/pages/my-markdown-page.md`

```jsx
import React from 'react'
import RadarChart from './RadarChart'
import PolarChart from './PolarChart'
export default class MyComponent extends React.Component {
render() {
return (
<div>
<RadarChart />
<PolarChart />
</div>
)
}
}
```
7 changes: 7 additions & 0 deletions examples/basic/gatsby-browser.js
@@ -0,0 +1,7 @@
/**
* Implement Gatsby's Browser APIs in this file.
*
* See: https://www.gatsbyjs.org/docs/browser-apis/
*/

// You can delete this file if you're not using it
16 changes: 16 additions & 0 deletions examples/basic/gatsby-config.js
@@ -0,0 +1,16 @@
module.exports = {
siteMetadata: {
title: 'Gatsby Default Starter',
},
plugins: [
'gatsby-plugin-react-helmet',
'gatsby-plugin-mdx',
{
resolve: 'gatsby-source-filesystem',
options: {
name: 'pages',
path: `${__dirname}/src/pages/`,
},
},
],
}
43 changes: 43 additions & 0 deletions examples/basic/gatsby-node.js
@@ -0,0 +1,43 @@
/**
* Implement Gatsby's Node APIs in this file.
*
* See: https://www.gatsbyjs.org/docs/node-apis/
*/

// You can delete this file if you're not using it

exports.createPages = ({ graphql, boundActionCreators }) => {
const { createPage } = boundActionCreators

return new Promise((resolve, reject) => {
graphql(`
{
allFile(filter: { extension: { eq: "md" } }) {
edges {
node {
absolutePath
relativeDirectory
name
}
}
}
}
`)
.then(result => {
if (result.errors) {
return reject(result.errors)
}

// Create markdown pages.
result.data.allFile.edges.forEach(
({ node: { absolutePath, relativeDirectory, name } }) => {
createPage({
path: `${relativeDirectory}/${name}`,
component: absolutePath,
})
}
)
})
.then(resolve)
})
}
7 changes: 7 additions & 0 deletions examples/basic/gatsby-ssr.js
@@ -0,0 +1,7 @@
/**
* Implement Gatsby's SSR (Server Side Rendering) APIs in this file.
*
* See: https://www.gatsbyjs.org/docs/ssr-apis/
*/

// You can delete this file if you're not using it

0 comments on commit 09bd74c

Please sign in to comment.