Code to slugify a string

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Code to slugify a string

Jolle Carlestam-2
Greetings!

The question about HMAC got me to revisit my Gist library. And realise it’s been a while since I posted anything there. Well, can’t have that. Here’s my kin_slugify

https://gist.github.com/jolle-c/ed80e4a40e712572fad00f9261c85f58

It solves the problem when you for example publish news articles and you want the headline of the article to be used as part of the URL linking to it. Headlines can have vastly more things in them than suits a URL so you’d need a way to clean it up before using it. Hence kin_slugify.

It will take a string of your choice and return a URL safe string.

Like:
Swedish Räksmörgås a treat for /me/?

Would be returned as:
swedish-raksmorgas-a-treat-for-me

This could then be easily served as part of a URL:
www.coolnews.tld/9587FTR4/swedish-raksmorgas-a-treat-for-me

It will also remove all emojis and similar. I can’t however show that in this email since Lasso talk would probably choke on it. (Old problem)


Enjoy

HDB
Jolle

#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: Code to slugify a string

Justin Dennis-3
👍🏻 Thanks for sharing. -Justin

On Wed, Sep 26, 2018 at 4:07 AM Jolle Carlestam <[hidden email]> wrote:

> Greetings!
>
> The question about HMAC got me to revisit my Gist library. And realise
> it’s been a while since I posted anything there. Well, can’t have that.
> Here’s my kin_slugify
>
> https://gist.github.com/jolle-c/ed80e4a40e712572fad00f9261c85f58
>
> It solves the problem when you for example publish news articles and you
> want the headline of the article to be used as part of the URL linking to
> it. Headlines can have vastly more things in them than suits a URL so you’d
> need a way to clean it up before using it. Hence kin_slugify.
>
> It qwill take a string of your choice and return a URL safe string.
>
>

#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>