File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed
Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change 11import os
22import platform
33import sys
4+ import unicodedata
45import webbrowser
56
67
@@ -82,3 +83,23 @@ def is_localhost_url(url):
8283def get_current_script_dir ():
8384 pathname = os .path .dirname (sys .argv [0 ])
8485 return os .path .abspath (pathname )
86+
87+
88+ def slugify (original : str ) -> str :
89+ """
90+ Make a string url friendly. Useful for creating routes for navigation.
91+
92+ >>> slugify("What's up?")
93+ 'whats-up'
94+
95+ >>> slugify(" Mitä kuuluu? ")
96+ 'mitä-kuuluu'
97+ """
98+ slugified = original .strip ()
99+ slugified = " " .join (slugified .split ()) # Remove extra spaces between words
100+ slugified = slugified .lower ()
101+ # Remove unicode punctuation
102+ slugified = "" .join (character for character in slugified if not unicodedata .category (character ).startswith ("P" ))
103+ slugified = slugified .replace (" " , "-" )
104+
105+ return slugified
You can’t perform that action at this time.
0 commit comments