forked from gatsbyjs/gatsby
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve docs for setting up a Gatsby application that pulls content f…
…rom Markdown files (gatsbyjs#13851) * adds example with markdown pages * Improves Adding Markdown Pages tutorial * wording * lints updates example and markdown file according to eslint rules lints README lints post-1 * addresses review * Update docs/docs/adding-markdown-pages.md Co-Authored-By: Marcy Sutton <[email protected]> * update to match Style Guide
- Loading branch information
1 parent
19466a2
commit 31ee1d0
Showing
17 changed files
with
975 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Using Markdown Pages | ||
|
||
Demonstrates how to render Markdown files as pages in you Gatsby application. | ||
|
||
## Running an example site | ||
|
||
1. Clone `gatsby` repository `git clone [email protected]:gatsbyjs/gatsby.git` | ||
2. Navigate to the example `cd gatsby/examples/using-markdown-pages` | ||
3. Install the dependencies for the application by running `yarn` | ||
4. Run the Gatsby development server `gatsby develop` | ||
|
||
## References | ||
|
||
- [Adding Markdown Pages](https://www.gatsbyjs.org/docs/adding-markdown-pages/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
module.exports = { | ||
siteMetadata: { | ||
title: `gatsby-example-using-markdown-pages`, | ||
description: `Start your new blog using markdown files`, | ||
author: `@gatsbyjs`, | ||
}, | ||
plugins: [ | ||
{ | ||
resolve: `gatsby-source-filesystem`, | ||
options: { | ||
name: `markdown-pages`, | ||
path: `${__dirname}/src/markdown-pages`, | ||
}, | ||
}, | ||
`gatsby-transformer-remark`, | ||
`gatsby-plugin-react-helmet`, | ||
{ | ||
resolve: `gatsby-source-filesystem`, | ||
options: { | ||
name: `images`, | ||
path: `${__dirname}/src/images`, | ||
}, | ||
}, | ||
`gatsby-transformer-sharp`, | ||
`gatsby-plugin-sharp`, | ||
{ | ||
resolve: `gatsby-plugin-manifest`, | ||
options: { | ||
name: `gatsby-starter-default`, | ||
short_name: `starter`, | ||
start_url: `/`, | ||
background_color: `#663399`, | ||
theme_color: `#663399`, | ||
display: `minimal-ui`, | ||
icon: `src/images/gatsby-icon.png`, | ||
}, | ||
}, | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const path = require(`path`) | ||
|
||
exports.createPages = ({ actions, graphql }) => { | ||
const { createPage } = actions | ||
|
||
const blogPostTemplate = path.resolve(`src/templates/blogTemplate.js`) | ||
|
||
return graphql(` | ||
{ | ||
allMarkdownRemark( | ||
sort: { order: DESC, fields: [frontmatter___date] } | ||
limit: 1000 | ||
) { | ||
edges { | ||
node { | ||
frontmatter { | ||
path | ||
} | ||
} | ||
} | ||
} | ||
} | ||
`).then(result => { | ||
if (result.errors) { | ||
return Promise.reject(result.errors) | ||
} | ||
|
||
return result.data.allMarkdownRemark.edges.forEach(({ node }) => { | ||
createPage({ | ||
path: node.frontmatter.path, | ||
component: blogPostTemplate, | ||
context: {}, // additional data can be passed via context | ||
}) | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"name": "gatsby-example-using-markdown-pages", | ||
"private": true, | ||
"description": "Start your new blog using markdown files", | ||
"version": "0.1.0", | ||
"author": "@gatsbyjs", | ||
"dependencies": { | ||
"gatsby": "^2.3.34", | ||
"gatsby-image": "^2.0.41", | ||
"gatsby-plugin-manifest": "^2.0.29", | ||
"gatsby-plugin-offline": "^2.0.25", | ||
"gatsby-plugin-react-helmet": "^3.0.12", | ||
"gatsby-plugin-sharp": "^2.0.35", | ||
"gatsby-source-filesystem": "^2.0.33", | ||
"gatsby-transformer-remark": "^2.3.12", | ||
"gatsby-transformer-sharp": "^2.1.18", | ||
"prop-types": "^15.7.2", | ||
"react": "^16.8.6", | ||
"react-dom": "^16.8.6", | ||
"react-helmet": "^5.2.1" | ||
}, | ||
"devDependencies": { | ||
"prettier": "^1.17.0" | ||
}, | ||
"keywords": [ | ||
"gatsby" | ||
], | ||
"license": "MIT", | ||
"scripts": { | ||
"build": "gatsby build", | ||
"develop": "gatsby develop", | ||
"format": "prettier --write src/**/*.{js,jsx}", | ||
"start": "npm run develop", | ||
"serve": "gatsby serve", | ||
"test": "echo \"Write tests! -> https://gatsby.dev/unit-testing\"" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Link } from "gatsby" | ||
import PropTypes from "prop-types" | ||
import React from "react" | ||
|
||
const Header = ({ siteTitle }) => ( | ||
<header | ||
style={{ | ||
background: `rebeccapurple`, | ||
marginBottom: `1.45rem`, | ||
}} | ||
> | ||
<div | ||
style={{ | ||
margin: `0 auto`, | ||
maxWidth: 960, | ||
padding: `1.45rem 1.0875rem`, | ||
}} | ||
> | ||
<h1 style={{ margin: 0 }}> | ||
<Link | ||
to="/" | ||
style={{ | ||
color: `white`, | ||
textDecoration: `none`, | ||
}} | ||
> | ||
{siteTitle} | ||
</Link> | ||
</h1> | ||
</div> | ||
</header> | ||
) | ||
|
||
Header.propTypes = { | ||
siteTitle: PropTypes.string, | ||
} | ||
|
||
Header.defaultProps = { | ||
siteTitle: ``, | ||
} | ||
|
||
export default Header |
Oops, something went wrong.