const path = require(`path`)

require('dotenv').config({
  path: `.env.${process.env.NODE_ENV}`,
})

module.exports = {
  siteMetadata: {
    title: 'I AM MATTHIAS',
    description: 'A personal portfolio project',
    siteUrl: 'https://iammatthias.com',
    author: 'Matthias Jordan',
    menuLinks: [
      {
        name: 'Home',
        slug: '/',
      },
      {
        name: 'Photography',
        slug: '/photography/',
      },
      {
        name: 'Blog',
        slug: '/blog/',
      },
      {
        name: 'About',
        slug: '/about/',
      },
    ],
    postsPerFirstPage: 6,
    postsPerPage: 6,
    basePath: '/',
  },
  plugins: [
    {
      resolve: 'gatsby-plugin-feed-generator',
      options: {
        generator: `GatsbyJS`,
        rss: false, // Set to true to enable rss generation
        json: true, // Set to true to enable json feed generation
        siteQuery: `
      {
        site {
          siteMetadata {
            title
            description
            siteUrl
            author
          }
        }
      }
    `,
        feeds: [
          {
            name: 'feed',
            query: `
            {
              allContentfulPost(sort: { fields: [updatedAt], order: DESC }, limit: 2) {
                edges {
                  node {
                  title
                  id
                  slug
                  internal {
                    type
                  }
                  updatedAt(formatString: "MMMM DD, YYYY")
                  }
                }
              }
              allContentfulPhotography(sort: { fields: [updatedAt], order: DESC }, limit: 2) {
                edges {
                  node {
                  title
                  id
                  slug
                  internal {
                    type
                  }
                  updatedAt(formatString: "MMMM DD, YYYY")
                  }
                }
              }
            }
            `,
            normalize: ({
              query: { site, allContentfulPost, allContentfulPhotography },
            }) => {
              let posts = allContentfulPost.edges.map(edge => {
                return {
                  title: edge.node.title,
                  slug: edge.node.slug,
                  url: site.siteMetadata.siteUrl + '/blog/' + edge.node.slug,
                  date: edge.node.updatedAt,
                  type: edge.node.internal.type,
                }
              })
              let photos = allContentfulPhotography.edges.map(edge => {
                return {
                  title: edge.node.title,
                  slug: edge.node.slug,
                  url:
                    site.siteMetadata.siteUrl +
                    '/photography/' +
                    edge.node.slug,
                  date: edge.node.updatedAt,
                  type: edge.node.internal.type,
                }
              })
              let combined = [...photos, ...posts].sort((a, b) => {
                return new Date(a) - new Date(b)
              })
              return combined
            },
          },
        ],
      },
    },
    'gatsby-plugin-emotion',
    'gatsby-plugin-theme-ui',

    'gatsby-plugin-react-helmet',
    {
      resolve: `gatsby-plugin-printer`,
      options: {
        puppeteerLaunchOptions: {
          headless: true,
        },
      },
    },
    {
      resolve: `gatsby-plugin-google-fonts`,
      options: {
        fonts: [`Montserrat:400,900`, `Crimson Text`, `Inconsolata`],
        display: 'swap',
      },
    },
    {
      resolve: `gatsby-plugin-mdx`,
    },
    {
      resolve: `gatsby-transformer-remark`,
      options: {
        plugins: [
          {
            resolve: `gatsby-remark-prismjs`,
          },
          `gatsby-remark-emojis`,
          `gatsby-remark-autolink-headers`,
          {
            resolve: `gatsby-remark-images-contentful`,
            options: {
              maxWidth: 650,
              backgroundColor: 'white',
              linkImagesToOriginal: false,
            },
          },
        ],
      },
    },
    `gatsby-plugin-catch-links`,
    {
      resolve: 'gatsby-source-contentful',
      options: {
        spaceId: process.env.CONTENTFUL_SPACE_ID,
        accessToken: process.env.CONTENTFUL_ACCESS_TOKEN,
        host: process.env.CONTENTFUL_HOST,
      },
    },

    `gatsby-plugin-sharp`,
    `gatsby-transformer-sharp`,
    {
      resolve: `gatsby-plugin-segment-js`,
      options: {
        prodKey: process.env.SEGMENT,
        devKey: process.env.SEGMENT,
        trackPage: true,
      },
    },
    'gatsby-plugin-sitemap',
    {
      resolve: 'gatsby-plugin-manifest',
      options: {
        name: 'I AM MATTHIAS',
        description: 'A personal portfolio project',
        short_name: 'IAM',
        start_url: '/',
        background_color: '#140D00',
        theme_color: '#140D00',
        display: 'fullscreen',
        icon: './static/images/favicon.png',
      },
    },
    'gatsby-plugin-offline',
    {
      resolve: `gatsby-plugin-schema-snapshot`,
      options: {
        path: `./src/gatsby/schema/schema.gql`,
        update: process.env.GATSBY_UPDATE_SCHEMA_SNAPSHOT,
      },
    },
    'gatsby-plugin-netlify',
  ],
}

@@ -1301,38 +1301,42 @@
                 
+  
 title%0A
+  
                 
@@ -1350,32 +1350,34 @@
                 
+  
 slug%0A           
@@ -1375,32 +1375,34 @@
                 
+ 
+ 
 internal %7B%0A     
@@ -1388,32 +1388,34 @@
      internal %7B%0A
+  
                 
@@ -1433,34 +1433,38 @@
                 
-%7D%0A
+  %7D%0A  
                 
@@ -1714,38 +1714,42 @@
                 
+  
 title%0A
+  
                 
@@ -1763,32 +1763,34 @@
                 
+  
 slug%0A           
@@ -1788,32 +1788,34 @@
                 
+ 
+ 
 internal %7B%0A     
@@ -1801,32 +1801,34 @@
      internal %7B%0A
+  
                 
@@ -1846,34 +1846,38 @@
                 
-%7D%0A
+  %7D%0A  
                 
@@ -2383,36 +2383,39 @@
                 
-date
+content
 : edge.node.upda
@@ -2406,33 +2406,37 @@
 : edge.node.
-updatedAt
+internal.type
 ,%0A          
@@ -2435,35 +2435,35 @@
                 
-typ
+dat
 e: edge.node.int
@@ -2455,37 +2455,33 @@
 : edge.node.
-internal.type
+updatedAt
 ,%0A          
@@ -2839,36 +2839,39 @@
                 
-date
+content
 : edge.node.upda
@@ -2862,33 +2862,37 @@
 : edge.node.
-updatedAt
+internal.type
 ,%0A          
@@ -2899,19 +2899,19 @@
         
-typ
+dat
 e: edge.
@@ -2911,37 +2911,33 @@
 : edge.node.
-internal.type
+updatedAt
 ,%0A          

fix type for feed