Gatsbyjs with Home Page Slider + Contentful Slugs

Hey There

I am using Gatsbyjs + Contentful for our next site. I am having an issue with our homepage slider on how to dynamically add the correct route before the slug.

For example we have product pages and blog post. and when creating a new slide in our home page slider and I have a reference to the blog post. Is there a way to add the /blog/ in the slug when contentful brings down the slug ? Is this functionality available within contentful to have routes appended to the slug?

Thanks!

I would approach this by adding /blog/ to the slug client side. There are lots of ways to approach doing so. Without more information like how you content is modeled or the graphql query you are using I would do something like:

let slug = item.slug;
if (item.content_type === 'blogPost') {
  slug = `/blog/${slug}`;
}

If you provide some more specific information I’d be happy to give a better answer.

Hey Kyle

Thanks for the reply. I was thinking this would be the answer.

I wasn’t sure if there was a feature in Contentful that would add dynamically to the slug based on what the content type was.

For example if it is a blog post to always add /blog/ to the front of the slug.

Thanks