I am importing data from an external API into my sanity schema and the API contains the slug in the form of a string. I have tried removing the double quotes of the string and making it single quoted but that is still not accepted by sanity as slug type.
So how do I convert it to the slug type?
code I'm currently using:
const slicedSlug = externalReport.slug.replace(/["]+/g, '');
The slug is an "object" with _type: 'slug'. In case you were trying to add it as a string, try this:
const slug = {
_type: 'slug',
current: 'your-slug-without-quotes',
};
Personally I would also replace spaces and make all lower caps but it might not be relevant to your situation.
yourSlug.replace(/["]+/g, '').replace(/\s+/g, '-').toLowerCase();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With