Last active
September 26, 2018 08:00
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
/*---------------------------------------------------------------------------- | |
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