storyblok icon indicating copy to clipboard operation
storyblok copied to clipboard

full_slug field on stories is inconsistent with trailing slashes

Open fredrikekelund opened this issue 3 years ago • 3 comments

The feature would affect:

  • [ ] app.storyblok.com (CMS - Interface)
  • [x] api.storyblok.com (CMS - Content Delivery API)
  • [x] mapi.storyblok.com (CMS - Management API)
  • [ ] capi.storyblok.com (Commerce - API)
  • [ ] Commerce - Interface
  • [ ] Other

Is your feature request related to a problem? Please describe. When fetching stories from the Content Delivery or Management API, the full_slug field is inconsistent with trailing slashes. For folder startpages, there is a trailing slash, but for all other pages, there is not.

Describe the solution you'd like It would be very helpful to at least have this mentioned in the docs. Updating the current API might not be realistic since it could break existing integrations, but in potential future versions of the API, I think it would be more useful to be consistent. There is already the is_startpage field to determine whether a particular page is a startpage or not.

Describe alternatives you've considered None

Additional context None

fredrikekelund avatar Sep 14 '21 09:09 fredrikekelund

Is there any advancement with this issue?

LukasHechenbergerID avatar Nov 20 '23 12:11 LukasHechenbergerID

Is there any workarounds for this?

IzakJackson avatar Jan 07 '24 12:01 IzakJackson

@IzakJackson yes, you can just check if there is a trailing slash like that and remove it. We have a function that takes the storyblok link object and looks at the different types (like url, story, asset,...) but you can just use the one for story:

 if (link.linktype === "story" && link.cached_url) {  
        if (link.cached_url !== "/" && link.cached_url.endsWith("/")) {  
            return link.cached_url.slice(0, -1);  
        }  
        return link.cached_url;   
}

LukasHechenbergerID avatar Jan 08 '24 08:01 LukasHechenbergerID