Skip to content

Commit cbbfd62

Browse files
committed
gatsbyjs: Add comments
1 parent 232c251 commit cbbfd62

File tree

6 files changed

+21
-1
lines changed

6 files changed

+21
-1
lines changed

gatsbyjs-markdown-blog/gatsby-config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Configure plugins used
2+
// gatsby-source-filesystem is pointed to /src to look for files
3+
// typography.js is configured using /utils/typography
4+
15
module.exports = {
26
siteMetadata: {
37
title: `Pandas Eating Lots`,

gatsbyjs-markdown-blog/gatsby-node.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
const path = require(`path`);
22
const { createFilePath } = require(`gatsby-source-filesystem`);
33

4+
// onCreateNode is called for every node created
5+
// markdown nodes are filtered and createNodeField adds a field slug which holds value of the filePath
6+
47
exports.onCreateNode = ({ node, getNode, boundActionCreators }) => {
58
const { createNodeField } = boundActionCreators
69
if (node.internal.type === `MarkdownRemark`) {
@@ -13,6 +16,10 @@ exports.onCreateNode = ({ node, getNode, boundActionCreators }) => {
1316
}
1417
};
1518

19+
20+
// createPages creates a page for each markdown node
21+
// createPage uses path from slug queried, blog-post.js as template to create page
22+
// Everything in context is passed into individual pages
1623
exports.createPages = ({ graphql, boundActionCreators }) => {
1724
const { createPage } = boundActionCreators
1825
return new Promise((resolve, reject) => {

gatsbyjs-markdown-blog/src/layouts/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import React from 'react';
22

3+
// Layout encloses everything else in itself for all pages
4+
// children is a function that contains all the pages
5+
// so all basically all pages follow this layout now
36
export default ({children}) => (
47
<div>
58
<h3 style={{textAlign: `center`, margin: `1em`, padding: `1em`, borderBottom: `1px solid lightgrey`}}>Panda Blog</h3>

gatsbyjs-markdown-blog/src/pages/blog.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ import Link from "gatsby-link";
44

55
import { rhythm } from "../utils/typography";
66

7+
// Displays list of blog posts (i.e markdown files)
78
export default ({ data }) => {
89
return (
910
<div>
1011
<g.H1 display={"inline-block"} borderBottom={"1px solid"}>
1112
Amazing Pandas Eating Things
12-
</g.H1>
13+
</g.H1>
1314
<h4>{data.allMarkdownRemark.totalCount} Posts</h4>
1415
{data.allMarkdownRemark.edges.map(({ node }) => (
1516
<div key={node.id}>
@@ -31,6 +32,8 @@ export default ({ data }) => {
3132
);
3233
};
3334

35+
// gatsby-transformer-remark converts each markdown file into JSON data with content as HTML
36+
// GraphQL queries for the list of such files
3437
export const query = graphql`
3538
query IndexQuery {
3639
allMarkdownRemark {

gatsbyjs-markdown-blog/src/pages/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from "react";
22
import Link from "gatsby-link";
33

4+
// Basic boilerplate code for content to display
45
export default () => (
56
<div>
67
<h1>Hi! I'm building a fake Gatsby site as part of a tutorial!</h1>

gatsbyjs-markdown-blog/src/templates/blog-post.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from "react";
22

3+
// data is returned from GraphQL query
34
export default ({ data }) => {
45
const post = data.markdownRemark;
56
return (
@@ -10,6 +11,7 @@ export default ({ data }) => {
1011
);
1112
};
1213

14+
// slug passed in from context, used to find current post
1315
export const query = graphql`
1416
query BlogPostQuery($slug: String!) {
1517
markdownRemark(fields: { slug: { eq: $slug } }) {

0 commit comments

Comments
 (0)