DEV Community

Blake Powers
Blake Powers

Posted on

How to change slug before uploading to Algolia

I'm working on implementing Algolia search into my Gatsby website. I need to format the slugs of my content correctly so that Algolia gets the correct links.

The slug my query gets from Contentful is similar to /icon-name/

I need it to match the path that gets created from my Gatsby-node.js file path: /design-resources/icons/${node.slug}/

Is it possible to get this path after its created from Gatsby-node.js or is there a way to transform the icon Query below before uploading to Algolia?

My Query

const iconQuery = `
query iconQuery {
    allContentfulIcon {
        edges {
            node {
                id
                title
                slug
                keywords
                pngFIle {
                    fluid {
                        srcSetWebp
                    }
                  }
              }
        }
    }
}`;
Enter fullscreen mode Exit fullscreen mode

Transformer for Algolia

const queries = [
  {
    query: iconQuery,
    transformer: ({ data }) =>
      data.allContentfulIcon.edges.map(({ node }) => node), // optional
  },
];

module.exports = queries;
Enter fullscreen mode Exit fullscreen mode

Top comments (0)