Added minimum words length argument in 'generate_url' function, with a default value of 2 characters
authorThierry Florac <tflorac@ulthar.net>
Wed, 05 Dec 2018 16:55:48 +0100
changeset 290 1c40b34d2646
parent 289 c8e21d7dd685
child 291 684f08c4789e
Added minimum words length argument in 'generate_url' function, with a default value of 2 characters
src/pyams_utils/url.py
--- a/src/pyams_utils/url.py	Wed Dec 05 12:45:56 2018 +0100
+++ b/src/pyams_utils/url.py	Wed Dec 05 16:55:48 2018 +0100
@@ -12,9 +12,6 @@
 
 __docformat__ = 'restructuredtext'
 
-
-# import standard library
-
 from pyramid.encode import url_quote, urlencode
 from pyramid.url import QUERY_SAFE, resource_url
 from zope.interface import Interface
@@ -25,13 +22,13 @@
 from pyams_utils.unicode import translate_string
 
 
-def generate_url(title):
+def generate_url(title, min_word_length=2):
     """Generate an SEO-friendly content URL from it's title
 
     The original title is translated to remove accents, converted to lowercase, and words
     shorter than three characters are removed; terms are joined by hyphens.
     """
-    return '-'.join(filter(lambda x: len(x) > 2,
+    return '-'.join(filter(lambda x: len(x) >= min_word_length,
                            translate_string(title, escape_slashes=True, force_lower=True, spaces='-',
                                             remove_punctuation=True, keep_chars='-').split('-')))