Skip to content

Commit 759d4c5

Browse files
committed
initial commit
0 parents  commit 759d4c5

26 files changed

+29622
-0
lines changed

.gitignore

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
8+
# Runtime data
9+
pids
10+
*.pid
11+
*.seed
12+
*.pid.lock
13+
14+
# Directory for instrumented libs generated by jscoverage/JSCover
15+
lib-cov
16+
17+
# Coverage directory used by tools like istanbul
18+
coverage
19+
20+
# nyc test coverage
21+
.nyc_output
22+
23+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24+
.grunt
25+
26+
# Bower dependency directory (https://bower.io/)
27+
bower_components
28+
29+
# node-waf configuration
30+
.lock-wscript
31+
32+
# Compiled binary addons (http://nodejs.org/api/addons.html)
33+
build/Release
34+
35+
# Dependency directories
36+
node_modules/
37+
jspm_packages/
38+
39+
# Typescript v1 declaration files
40+
typings/
41+
42+
# Optional npm cache directory
43+
.npm
44+
45+
# Optional eslint cache
46+
.eslintcache
47+
48+
# Optional REPL history
49+
.node_repl_history
50+
51+
# Output of 'npm pack'
52+
*.tgz
53+
54+
# dotenv environment variables file
55+
.env
56+
57+
# gatsby files
58+
.cache/
59+
public
60+
61+
# Mac files
62+
.DS_Store
63+
64+
# Yarn
65+
yarn-error.log
66+
.pnp/
67+
.pnp.js
68+
# Yarn Integrity file
69+
.yarn-integrity

.prettierrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
tabWidth: 2
2+
semi: false
3+
singleQuote: true

LICENSE

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 gatsbyjs
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
22+

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Gatsby and MDX
2+
3+
This is the [Gatsby Default Starter](https://github.com/gatsbyjs/gatsby-starter-default) with changes made to it for this blog post: https://reacttraining.com/blog/gatsby-mdx-blog/

gatsby-browser.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* Implement Gatsby's Browser APIs in this file.
3+
*
4+
* See: https://www.gatsbyjs.org/docs/browser-apis/
5+
*/
6+
7+
// You can delete this file if you're not using it

gatsby-config.js

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
module.exports = {
2+
siteMetadata: {
3+
title: `Gatsby Default Starter`,
4+
description: `Kick off your next, great Gatsby project with this default starter. This barebones starter ships with the main Gatsby configuration files you might need.`,
5+
author: `@gatsbyjs`,
6+
},
7+
plugins: [
8+
`gatsby-plugin-react-helmet`,
9+
{
10+
resolve: `gatsby-mdx`,
11+
options: {
12+
// Apply gatsby-mdx to both .mdx and .md files
13+
extensions: ['.mdx', '.md'],
14+
defaultLayout: require.resolve('./src/components/blog-post-layout.js')
15+
}
16+
},
17+
`gatsby-transformer-sharp`,
18+
`gatsby-plugin-sharp`,
19+
{
20+
resolve: `gatsby-source-filesystem`,
21+
options: {
22+
name: `images`,
23+
path: `${__dirname}/src/images`,
24+
},
25+
},
26+
{
27+
resolve: `gatsby-source-filesystem`,
28+
options: {
29+
name: `blog`,
30+
path: `${__dirname}/src/pages/blog`,
31+
},
32+
},
33+
{
34+
resolve: `gatsby-plugin-manifest`,
35+
options: {
36+
name: `gatsby-starter-default`,
37+
short_name: `starter`,
38+
start_url: `/`,
39+
background_color: `#663399`,
40+
theme_color: `#663399`,
41+
display: `minimal-ui`,
42+
icon: `src/images/gatsby-icon.png`, // This path is relative to the root of the site.
43+
},
44+
},
45+
// this (optional) plugin enables Progressive Web App + Offline functionality
46+
// To learn more, visit: https://gatsby.app/offline
47+
// 'gatsby-plugin-offline',
48+
],
49+
}

gatsby-node.js

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
const { createFilePath } = require('gatsby-source-filesystem')
2+
const path = require('path')
3+
4+
// Here we're adding extra stuff to the "node" (like the slug)
5+
// so we can query later for all blogs and get their slug
6+
exports.onCreateNode = ({ node, actions, getNode }) => {
7+
const { createNodeField } = actions
8+
if (node.internal.type === 'Mdx') {
9+
const value = createFilePath({ node, getNode })
10+
createNodeField({
11+
// Name of the field you are adding
12+
name: 'slug',
13+
// Individual MDX node
14+
node,
15+
// Generated value based on filepath with "blog" prefix
16+
value: `/blog${value}`
17+
})
18+
}
19+
}
20+
21+
// Programmatically create the pages for browsing blog posts
22+
exports.createPages = ({ graphql, actions }) => {
23+
const { createPage } = actions
24+
return graphql(`
25+
query {
26+
allMdx(sort: { order: DESC, fields: [frontmatter___date] }) {
27+
edges {
28+
node {
29+
id
30+
excerpt(pruneLength: 250)
31+
fields {
32+
slug
33+
}
34+
frontmatter {
35+
author
36+
title
37+
}
38+
}
39+
}
40+
}
41+
}
42+
`).then((results, errors) => {
43+
if (errors) return Promise.reject(errors)
44+
const posts = results.data.allMdx.edges
45+
46+
// This little algo takes the array of posts and groups
47+
// them based on this `size`. I used a small number just
48+
// for testing since there are only three posts
49+
let size = 2
50+
let start = 0
51+
let groupedPosts = Array.from(Array(Math.ceil(posts.length / size)))
52+
groupedPosts = groupedPosts.map(() => {
53+
const group = posts.slice(start, start + size)
54+
start += size
55+
return group
56+
})
57+
58+
groupedPosts.forEach((group, index) => {
59+
const page = index + 1
60+
createPage({
61+
path: `/blog/${page}`,
62+
component: path.resolve('./src/components/browse-blog-posts.js'),
63+
context: { groupedPosts, group, page }
64+
})
65+
})
66+
})
67+
}

gatsby-ssr.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* Implement Gatsby's SSR (Server Side Rendering) APIs in this file.
3+
*
4+
* See: https://www.gatsbyjs.org/docs/ssr-apis/
5+
*/
6+
7+
// You can delete this file if you're not using it

0 commit comments

Comments
 (0)