text: require('dotenv').config()
  const {
    api: { projectId, dataset }
  } = requireConfig('../studio/sanity.json')
  
  module.exports = {
    siteMetadata: {
      siteUrl: 'https://www.jaapjandeboer.nl'
    },
    plugins: [
      'gatsby-plugin-postcss',
      'gatsby-plugin-react-helmet',
      {
        resolve: 'gatsby-source-sanity',
        options: {
          projectId,
          dataset,
          // To enable preview of drafts, copy .env-example into .env,
          // and add a token with read permissions
          token: process.env.SANITY_TOKEN,
          watchMode: true,
          overlayDrafts: true
        }
      },
      'gatsby-image',
      {
        resolve: `gatsby-plugin-manifest`,
        options: {
          name: `Jaap Jan de Boer`,
          short_name: `Jaap Jan de Boer`,
          start_url: `/`,
          background_color: `#000`,
          theme_color: `#000`,
          display: `standalone`,
          icon: `src/images/logo.flat.square.svg`
        }
      },
      {
        resolve: `gatsby-plugin-sitemap`,
        options: {
          output: `/sitemap.xml`,
          // Exclude specific pages or groups of pages using glob parameters
          // See: https://github.com/isaacs/minimatch
          // The example below will exclude the single `path/to/page` and all routes beginning with `category`
          exclude: ['/category/*', `/tag/*`, `/quote/*`],
          query: `
          {
            site {
              siteMetadata {
                siteUrl
              }
            }
            allSitePage {
              edges {
                node {
                  path
                }
              }
            }
          }`
        }
      },
      `gatsby-plugin-robots-txt`,
      {
        resolve: `gatsby-plugin-canonical-urls`,
        options: {
          siteUrl: `https://www.jaapjandeboer.nl`
        }
      },
      {
        resolve: `gatsby-plugin-google-tagmanager`,
        options: {
          id: 'GTM-56CKRTV',
  
          // Include GTM in development.
          // Defaults to false meaning GTM will only be loaded in production.
          includeInDevelopment: false
        }
      },
      {
        resolve: `gatsby-plugin-netlify`,
        options: {
          headers: {
            '/*.css': ['Cache-Control: public, max-age=31536000, immutable'],
            '/*.js': ['Cache-Control: public, max-age=31536000, immutable']
          }, // option to add more headers. `Link` headers are transformed by the below criteria
          allPageHeaders: [], // option to add headers for all pages. `Link` headers are transformed by the below criteria
          mergeSecurityHeaders: true, // boolean to turn off the default security headers
          mergeLinkHeaders: true, // boolean to turn off the default gatsby js headers
          mergeCachingHeaders: true, // boolean to turn off the default caching headers
          transformHeaders: (headers, path) => headers, // optional transform for manipulating headers under each path (e.g.sorting), etc.
          generateMatchPathRewrites: true // boolean to turn off automatic creation of redirect rules for client only paths
        }
      },
      'gatsby-plugin-offline'
    ]
  }
  
  /**
   * We're requiring a file in the studio folder to make the monorepo
   * work "out-of-the-box". Sometimes you would to run this web frontend
   * in isolation (e.g. on codesandbox). This will give you an error message
   * with directions to enter the info manually or in the environment.
   */
  
  function requireConfig (path) {
    try {
      return require('../studio/sanity.json')
    } catch (e) {
      console.error('Failed to require sanity.json. Fill in projectId and dataset name manually in gatsby-config.js')
      return {
        api: {
          projectId: process.env.SANITY_PROJECT_ID || '',
          dataset: process.env.SANITY_DATASET || ''
        }
      }
    }
  }
  