[Pack] Slugify text for use in URLs

Noticed there wasn’t anything like this so I decided to make my own:

It’s actually really simple and uses an existing npm package under the hood.

Hope this will be useful to someone aswell!

1 Like

Just curious, does it work like the EncodeForURL formula?

Thank you for asking!

It’s purpose is very different. EncodeForURL keeps the original string recoverable - you can decode it later.

Slug is a pretty/simplified version of an otherwise URL-unfriendly string/text.

Imagine if you’re using Coda as a backend for your blog (as a CMS), and you want to create a new post titled “This is the #1 post!”. You probably want the URL for that post to be pretty (there is also a SEO benefit) so you’d slugify it and get “this-is-the-1-post”. You can then use this slug for an URL to your blog post, e.g. myblog.com/this-is-the-1-post

In comparison, if you run the same string through EncodeForURL, you get “This%20is%20the%20%231%20post%21”. As you can tell this is pretty much unreadable without first decoding it.