Skip to content

Instantly share code, notes, and snippets.

@jolle-c
Last active September 26, 2018 08:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jolle-c/ed80e4a40e712572fad00f9261c85f58 to your computer and use it in GitHub Desktop.
Save jolle-c/ed80e4a40e712572fad00f9261c85f58 to your computer and use it in GitHub Desktop.
For when you want a string, like a headline for a news article, to be used as part of a URL
[
/*----------------------------------------------------------------------------
kin_slugify.lasso
Author: Jolle Carlestam
License: Public Domain
Description:
For when you want a string, like a headline for a news article, to be used as part of a URL. Safe to send out in the wild.
Sample Usage:
local(title = 'Swedish Räksmörgås a treat for /me/?')
kin_slugify(#title)
-> swedish-raksmorgas-a-treat-for-me
Version history
2018-09-26 JC Published to gist
----------------------------------------------------------------------------*/
define kin_slugify(
text::string
) => {
local(_string = string(#text))
#_string->lowercase
#_string->replace(regexp(`(ä|å|æ)`), 'a')
#_string->replace('å', 'a')
#_string->replace(regexp(`(ö|ø)`), 'o')
#_string->replace('ü', 'u')
#_string->replace('&', '-')
#_string->replace(regexp(`[\x{10000}-\x{10ffff}]`, '')) // clear out emojis and similar
#_string->replace(regexp(`(,|\+|\$|#|€|%|/|\(|\||\)|\=|\?|")`), '')//"
#_string->replace(regexp(`(\[|<|>|@|:|;|/)`), '')
#_string->replace(regexp(`(\{|\}|\])`), '')
#_string->replace(regexp(`(\^|\\)`), '')
#_string->trim
#_string->replace(' ', '-')
return string(#_string->encodeurl)
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment