Go Pro Sign Up Login

Buy Now and unlock this series

$

44

.99

$

34

.99

yours forever

Become a Pro and unlock everything

$

24

.99

per month

Creating Pages From Markdown Files

Here, we will be going over how to use the ‘slug’ to actually create pages from our Markdown files. We will be iterating over our gatsby-node page to create the dynamic content.

Downloads

Become a pro to download code and videos

Comments

User avatar

Raul

almost 2 years ago

@Jack I would recommend you read this very interesting article about what's best for each case: https://medium.com/better-programming/should-i-use-promises-or-async-await-126ab5c98789

Jack

about 2 years ago [edited]

Is there any disadvantage to using async await syntax rather than the Promise one used in the video? The following code seems to work identically:

const path = require("path");

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

  const createPagesFromMarkdown = async () => {
    const { data } = await graphql(`
      {
        allMarkdownRemark {
          edges {
            node {
              frontmatter {
                slug
              }
            }
          }
        }
      }
    `);

    const markdownPages = data.allMarkdownRemark.edges;

    markdownPages.forEach(({ node }) => {
      createPage({
        path: node.frontmatter.slug,
        component: path.resolve("./src/components/postLayout.js"),
      });
    });
  };

  return createPagesFromMarkdown();
};

Sebastian

over 2 years ago

Hi, Why exactly do we want it to be async?

Want to join the conversation?

Become a Pro member today!