Gatsby Contentful Markdown



Panda antivirus for mac

FlexiBlog is a fully functional multi-purpose blog theme powered by React and Gatsby JS v3 and packed with various page layouts. With FlexiBlog, you’re not limited to local Markdown files; Contentful CMS and Strapi CMS and Netlify CMS and Sanity CMS are also supported by the theme to write your blog posts. Essential services such as Algolia search system, Mailchimp newsletter provider. Veho discovery usb microscope. When querying images you can use the fixed, fluid or resize nodes to get different sizes for the image (for example for using gatsby-image).Their usage is documented at the gatsby-plugin-sharp package. The only difference is that gatsby-source-contentful also allows setting only the width parameter for these node types, the height will then automatically be calculated according to the aspect.

  1. Gatsby Contentful Markdown Summary
  2. Gatsby Contentful Markdown Quotes
  3. Gatsby Contentful Markdown Meaning
  4. Gatsby Contentful Markdown Crossword
Gatsby Contentful Markdown

Gatsby is a static site generator based on React with much popularity nowadays.

  1. Foundation Gatsby Projects: Create Four Real Production Websites with Gatsby.
  2. Do I need to write scripts to convert my Contentful content into Gatsby 'markdown'? Any ideas, ideas, links appreciated! Contentful gatsby netlify. Improve this question. Follow asked Jun 14 '16 at 16:00. Max Hodges Max Hodges. 4,465 10 10 gold badges 44 44 silver badges 64 64 bronze badges.
Contentful

The list of sites powered by Gatsby is awe-inspiring:

Gatsby
  • My website 😂

One of its most definite advantages is the ability to obtain content from many different sources:

Software

  • Wordpress API
  • Contentful
  • Markdown files

In this article, we will focus on the last one to build a page with separated sections organized by folders containing the different types of posts (blog, projects, and talks).

Files hierarchy

Configuration

To fetch data from the file system, we need to use a plugin called gatsby-source-filesystem.

Gatsby Contentful Markdown Summary

After fetching the data, we need to convert the Markdown to valid HTML. For that, we are going to use gatsby-transformer-remark.

After installing the packages with npm or yarn, the next step is to configure Gatsby to read from each one of the content folders and parse the Markdown files:

Templates

For each section, we want to define a template for the posts list and optionally one for the post detail (the links for the talks and projects are external, so only the blog has detail page).

Contentful cms

List page example

Gatsby Contentful Markdown Quotes

Let’s analyze what’s happening here:

  1. We query all the Markdown content, filtering by collection (blog).
  2. We also filter by published state. That way, we can include a flag in the frontmatter to mark the file as “unpublished.”
  3. We add pagination ability. We are going to generate proper information later.
  4. We pass the edges of the data, as well as the pagination information to a “functional” component, which renders the information correctly.

Detail page example

This case is even simpler, as there is no pagination or collection type involved. The query receives a slug as parameter. The data is passed then to a functional component.

Pages generation

Now, we need to update gatsby-node.js, to read for the separated content files in the proper directories.

To maintain our file clean, we are going to create a folder called gatsby, with two files inside: create-pages.js and on-create-node.js.

gatsby-node.js

Gatsby Contentful Markdown Meaning

on-create-node.js

With this hook, we are telling Gatsby to add two new fields when the node is created. We can access those fields later with GraphQL, to filter the pages by collection and to obtain the detail for a determined slug (which includes the collection).

create-pages.js

Let’s analyze what’s happening in this hook:

  1. We query all the Markdown content, excluding the unpublished items.
  2. For each type of content, we run a collection generator, which filters the content by type and creates the proper pages using the templates.

Note that we can define for each collection:

  • How many items we want to display in each page
  • If the collection must render individual detail pages

Real example

Gatsby Contentful Markdown Crossword

As I said previously, I’ve used this technique to build this page, so feel free to inspect the files to see a complete example.





Comments are closed.