function convertArrayToString ( array ) { return array ? array . join ( ` ` ) . toLowerCase ( ) : `` ; } exports . onCreateNode = ( { node , actions } ) => { const { createNodeField } = actions ; if ( node . internal . type === 'TutorialsYaml' ) { createNodeField ( { node , name : `formatsAsString` , value : convertArrayToString ( node . formats ) , } ) ; createNodeField ( { node , name : `topicsAsString` , value : convertArrayToString ( node . topics ) , } ) ; createNodeField ( { node , name : `authorsAsString` , value : convertArrayToString ( node . authors ) , } ) ; } } ; let indexPageContext = { } ; exports . createPages = async ( { graphql , reporter } ) => { const result = await graphql ( `
      {
        tutorialsWithDates: allTutorialsYaml(
          filter: { date: { ne: null } }
          sort: { fields: [date], order: DESC }
        ) {
          nodes {
            title
            link
            formats
            date(formatString: "MMM DD, YYYY")
            length
            authors
            source
            topics
            fields {
              authorsAsString
              formatsAsString
              topicsAsString
            }
          }
        }

        tutorialsWithoutDates: allTutorialsYaml(
          filter: { date: { eq: null } }
          sort: { fields: [title], order: ASC }
        ) {
          nodes {
            title
            link
            formats
            language
            date(formatString: "MMM DD, YYYY")
            length
            authors
            source
            topics
            fields {
              authorsAsString
              formatsAsString
              topicsAsString
            }
          }
        }
      }
    ` ) ; if ( result . errors ) { reporter . panicOnBuild ( `Error while running GraphQL query.` ) ; return ; } const { tutorialsWithDates , tutorialsWithoutDates } = result . data ; const tutorials = [ ... tutorialsWithDates . nodes , ... tutorialsWithoutDates . nodes ] ; const formatArrays = tutorials . map ( tutorial => tutorial . formats ) ; const formats = [ ... new Set ( formatArrays . reduce ( ( acc , curr ) => [ ... acc , ... curr ] ) . map ( format => format . toLowerCase ( ) ) ) , ] . sort ( ) ; const topicArrays = tutorials . map ( tutorial => tutorial . topics ) ; const topics = [ ... new Set ( topicArrays . reduce ( ( acc , curr ) => [ ... acc , ... curr ] ) . map ( topic => topic . toLowerCase ( ) ) ) , ] . sort ( ) ; const authorArrays = tutorials . map ( tutorial => tutorial . authors ) ; const authors = [ ... new Set ( authorArrays . reduce ( ( acc , curr ) => [ ... acc , ... curr ] ) ) , ] . sort ( ( a , b ) => a . toLowerCase ( ) . localeCompare ( b . toLowerCase ( ) ) ) ; const sources = [ ... new Set ( tutorials . map ( tutorial => ( tutorial . source ? tutorial . source : '' ) ) ) , ] . sort ( ( a , b ) => a . toLowerCase ( ) . localeCompare ( b . toLowerCase ( ) ) ) ; indexPageContext = { tutorials : tutorials , formats : formats , topics : topics , authors : authors , sources : sources , } ; } ; exports . onCreatePage = ( { page , actions } ) => { const { createPage , deletePage } = actions ; if ( page . path === `/` ) { deletePage ( page ) ; createPage ( { ... page , context : indexPageContext , } ) ; } } ; exports . onCreateWebpackConfig = ( { stage , actions } ) => { if ( stage . startsWith ( 'develop' ) ) { actions . setWebpackConfig ( { resolve : { alias : { 'react-dom' : '@hot-loader/react-dom' , } , } , } ) ; } } ;