Skip to content

Instantly share code, notes, and snippets.

@shunfan
Last active June 25, 2017 20:18
Show Gist options
  • Select an option

  • Save shunfan/5847732 to your computer and use it in GitHub Desktop.

Select an option

Save shunfan/5847732 to your computer and use it in GitHub Desktop.

Revisions

  1. Shunfan Du revised this gist Jun 24, 2013. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions slugify.py
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,7 @@
    # coding=utf-8
    """
    Slugify for Chinese
    没有优化多音字
    优化多音字的项目有:
    https://github.com/jiedan/chinese_pinyin
  2. Shunfan Du revised this gist Jun 24, 2013. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion slugify.py
    Original file line number Diff line number Diff line change
    @@ -8,8 +8,9 @@
    import unidecode

    def slugify(str):
    return re.sub(r"\s+", '-', unidecode.unidecode(str).lower().strip())
    return re.sub(r'\s+', '-', unidecode.unidecode(str).lower().strip())


    # Test
    print slugify(u"测试")
    # >>> ce-shi
  3. Shunfan Du revised this gist Jun 24, 2013. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions slugify.py
    Original file line number Diff line number Diff line change
    @@ -10,5 +10,6 @@
    def slugify(str):
    return re.sub(r"\s+", '-', unidecode.unidecode(str).lower().strip())


    # Test
    print slugify(u"测试")
  4. Shunfan Du revised this gist Jun 24, 2013. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions slugify.py
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,9 @@
    # coding=utf-8
    """
    没有优化多音字
    优化多音字的项目有:
    https://github.com/jiedan/chinese_pinyin
    """
    import re
    import unidecode

  5. Shunfan Du revised this gist Jun 24, 2013. 1 changed file with 2 additions and 5 deletions.
    7 changes: 2 additions & 5 deletions slugify.py
    Original file line number Diff line number Diff line change
    @@ -3,10 +3,7 @@
    import unidecode

    def slugify(str):
    str = unidecode.unidecode(str).lower()
    str = str.strip()
    str = re.sub(r"\s+", '-', str)
    return str
    return re.sub(r"\s+", '-', unidecode.unidecode(str).lower().strip())

    # Test
    print slugify(u"测试")
    print slugify(u"测试")
  6. Shunfan Du revised this gist Jun 24, 2013. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion slugify.py
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    # coding=utf-8
    import re
    import unidecode

    @@ -8,4 +9,4 @@ def slugify(str):
    return str

    # Test
    slugify(u"测试")
    print slugify(u"测试")
  7. Shunfan Du revised this gist Jun 24, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion slugify.py
    Original file line number Diff line number Diff line change
    @@ -8,4 +8,4 @@ def slugify(str):
    return str

    # Test
    slugify(u"试试")
    slugify(u"测试")
  8. Shunfan Du revised this gist Jun 24, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion slugify.py
    Original file line number Diff line number Diff line change
    @@ -8,4 +8,4 @@ def slugify(str):
    return str

    # Test
    slugify("试试")
    slugify(u"试试")
  9. Shunfan Du created this gist Jun 24, 2013.
    11 changes: 11 additions & 0 deletions slugify.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    import re
    import unidecode

    def slugify(str):
    str = unidecode.unidecode(str).lower()
    str = str.strip()
    str = re.sub(r"\s+", '-', str)
    return str

    # Test
    slugify("试试")