Skip to content

Commit

Permalink
render source code
Browse files Browse the repository at this point in the history
  • Loading branch information
tuan2311 committed Aug 10, 2020
1 parent f7b2e9a commit 2f44b3d
Show file tree
Hide file tree
Showing 12 changed files with 952 additions and 671 deletions.
24 changes: 0 additions & 24 deletions blog/2020-08-10-my-first-blog-post.md

This file was deleted.

5 changes: 4 additions & 1 deletion blog/2020-08-10-my-first-blog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ templateKey: blog-post
title: My First Blog
date: 2020-08-10T02:11:01.556Z
image: /img/beautiful-calla-lily-nice-background-color-70725804.jpg
tags:
- JavaScript
- React
---
**This is my bold text**

Expand All @@ -22,4 +25,4 @@ get(object, 'value.1');

* *list 2*

![](/img/512px-eo_circle_lime_letter-t.svg.png "Test image")
![](/img/512px-eo_circle_lime_letter-t.svg.png "Test image")
10 changes: 9 additions & 1 deletion gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,22 @@ module.exports = {
},
plugins: [
`gatsby-plugin-netlify-cms`,
{
resolve: `gatsby-plugin-mdx`,
options: {
extensions: ['.mdx', '.md'],
defaultLayouts: {
default: require.resolve('./src/templates/BlogTemplate.tsx'),
},
},
},
{
resolve: `gatsby-source-filesystem`,
options: {
path: `${__dirname}/blog`,
name: `blogs`,
},
},
`gatsby-transformer-remark`,
`gatsby-plugin-react-helmet`,
`gatsby-plugin-postcss`,
`gatsby-plugin-emotion`,
Expand Down
33 changes: 6 additions & 27 deletions gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,9 @@ exports.createPages = async ({ actions, graphql, reporter }) => {

const result = await graphql(`
{
allMarkdownRemark(
sort: { order: DESC, fields: [frontmatter___date] }
limit: 1000
) {
edges {
node {
fields {
slug
}
}
allMdx(sort: { order: DESC, fields: [frontmatter___date] }, limit: 1000) {
nodes {
slug
}
}
}
Expand All @@ -72,27 +65,13 @@ exports.createPages = async ({ actions, graphql, reporter }) => {
return;
}

result.data.allMarkdownRemark.edges.forEach(({ node }) => {
result.data.allMdx.nodes.forEach((node) => {
createPage({
path: `/blogs/${node.fields.slug}`,
path: `/blogs/${node.slug}`,
component: blogPostTemplate,
context: {
slug: node.fields.slug,
slug: node.slug,
},
});
});
};

exports.onCreateNode = ({ node, actions, getNode }) => {
const { createNodeField } = actions;

if (node.internal.type === `MarkdownRemark`) {
const filePath = createFilePath({ node, getNode, basePath: `blog` });
const slug = filePath.substr(1, filePath.length - 2);
createNodeField({
name: `slug`,
node,
value: slug,
});
}
};
Loading

0 comments on commit 2f44b3d

Please sign in to comment.