Giter Club home page Giter Club logo

slugger's Introduction

Slugger is slugging done right

Slugger solves the seemingly simple problem of turning a title into an url frienly slug:

>>> from slugger import Slugger
>>> s = Slugger(lang='en_US')
>>> s.sluggify(u'Headless-body-in-topless-bar')
u'headless-body-in-topless-bar'

Unlike many other slugging libraries, it also handles language-specific ascii-translation. Compare the ä, ö and ü in German

>>> s = Slugger(lang='de_DE')
>>> s.sluggify(u'Türöffner')
u'tueroeffner'

against Swedish:

>>> s = Slugger(lang='sv_SE')
>>> s.sluggify(u'Färsk Ägg')
u'farsk-agg'

Criterias of what makes a good slug vary, common requirements are a maximum length and a reduced character set that is highly URL-friendly.

To generate high-quality slugs, Slugger leverages the locale information from glibc (included in the package), the unihandecode library and some hand-written replacements.

>>> s = Slugger('en_US')
>>> s.sluggify(u'Bed & Breakfast')
u'bed-and-breakfast'
>>> s.sluggify(u'Folding@Home')
u'foldingathome'

These are also language-aware:

>>> s = Slugger('fr_FR')
>>> s.sluggify(u'Toi & Moi')
u'toi-et-moi'

Help out

If you find a badly generated slug, please report on github. Also, any help in implementing better support for more languages is appreciated; see the official documentation on how to get involved in development.

slugger's People

Contributors

mbr avatar miurahr avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.