aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xpyblog16
-rw-r--r--utils/utils.py14
2 files changed, 15 insertions, 15 deletions
diff --git a/pyblog b/pyblog
index 11c969c5..de24d075 100755
--- a/pyblog
+++ b/pyblog
@@ -53,20 +53,6 @@ from generators import generators
from cli import cli
-def sanitize(string):
- """Sanitize string (title) for URI consumption."""
- if isinstance(string, bytes):
- string = string.decode('utf-8')
- # to lowercase
- string = string.lower()
- # strip all non-word, non-hyphen and non-whitespace characters
- string = re.sub(r"[^\w\s-]", "", string)
- # replace consecutive whitespaces with a single hyphen
- string = re.sub(r"\s+", "-", string)
- # percent encode the result
- return urllib.parse.quote(string)
-
-
def edit_post_with_editor(path):
"""Launch text editor to edit post at a given path.
@@ -98,7 +84,7 @@ def new_post(title):
filename_date = date.strftime("%Y-%m-%d")
iso_date = date.isoformat()
display_date = "%s %d, %d" % (date.strftime("%B"), date.day, date.year)
- title_sanitized = sanitize(title)
+ title_sanitized = utils.sanitize(title)
filename = "%s-%s.md" % (filename_date, title_sanitized)
fullpath = os.path.join(POSTSDIR, filename)
if not os.path.isdir(POSTSDIR):
diff --git a/utils/utils.py b/utils/utils.py
index 44cf8e59..db4bab57 100644
--- a/utils/utils.py
+++ b/utils/utils.py
@@ -201,3 +201,17 @@ def static_vars(**kwargs):
setattr(func, k, kwargs[k])
return func
return decorate
+
+
+def sanitize(string):
+ """Sanitize string (title) for URI consumption."""
+ if isinstance(string, bytes):
+ string = string.decode('utf-8')
+ # to lowercase
+ string = string.lower()
+ # strip all non-word, non-hyphen and non-whitespace characters
+ string = re.sub(r"[^\w\s-]", "", string)
+ # replace consecutive whitespaces with a single hyphen
+ string = re.sub(r"\s+", "-", string)
+ # percent encode the result
+ return urllib.parse.quote(string)