gatsby-example-using-remark

Using Excerpts

1 min read · tagged remark, excerpts

Contents

gatsby-transformer-remark allows you to get an excerpt from a markdown post. By default, it will prune the first 140 characters, but you can optionally specify a pruneLength in the graphql query.

{
  allMarkdownRemark {
    edges {
      node {
        excerpt(pruneLength: 280)
      }
    }
  }
}

You can also manually mark in your markdown where to stop excerpting—similar to Jekyl. gatsby-transformer-remark uses gray-matter to parse markdown frontmatter, so you can specify an excerpt_separator, as well as any of the other options mentioned here, in the gatsby-config.js file.

{
  resolve: `gatsby-transformer-remark`,
  options: {
    excerpt_separator: `<!-- end -->`
  }
}

Any file that does not have the given excerpt_separator will fall back to the default pruning method.

You can see the results here


Avatar of Jay Gatsby
Jay Gatsby is a mysterious millionaire with shady business connections.

powered by @gatsbyjs