0

Building a portfolio site using Gatsby and Netlify CMS. I'd like to have 2 different post types, one for projects and one for blog posts. I don't see any way to differentiate the Netlify collection types in gatsby-node.ts.

This is my netlify config in static/admin/config.yml:

collections:
  - name: 'blog'
    label: 'Blog'
    folder: 'content/blog'
    create: true
    slug: 'blog/{{slug}}'
    path: '{{title}}/index'
    editor:
      preview: true
    fields:
      - { name: 'title', label: 'Title', widget: 'string' }
      - { name: 'date', label: 'Publish Date', widget: 'datetime' }
      - { name: 'description', label: 'Description', widget: 'string' }
      - { name: 'body', label: 'Body', widget: 'markdown' }

  - name: 'project'
    label: 'Project'
    folder: 'content/projects'
    create: true
    slug: 'projects/{{slug}}'
    path: '{{title}}/index'
    editor: 
      preview: true
    fields:
      - { name: 'title', label: 'Title', widget: 'string' }
      - { name: 'date', label: 'Publish Date', widget: 'datetime' }
      - { name: 'description', label: 'Description', widget: 'string' }
      - { name: 'image', label: 'Image', widget: 'image' }
      - { name: 'body', label: 'Body', widget: 'markdown' }

I'm loading them separately in gatsby-config.ts:

module.exports= {
  // ...
  plugins: [
    {
      resolve: 'gatsby-source-filesystem',
      options: {
        name: 'blog',
        path: `${__dirname}/content/blog`,
      },
    },
    {
      resolve: 'gatsby-source-filesystem',
      options: {
        name: 'projects',
        path: `${__dirname}/content/projects`,
      },
    },
  ]
  // ...
}

I can create different post types in Netlify CMS which then create markdown files in the correct folders. I can't figure out how to query them separately so that I can use different templates to display them. I've been poking around in GraphiQL for hours looking for any bit of data which would differentiate these two post types.

Ferran Buireu
  • 28,630
  • 6
  • 39
  • 67
aviemet
  • 1,463
  • 1
  • 15
  • 19

0 Answers0