create_slug helper

3 views
Skip to first unread message

Domen Kožar

unread,
Jun 6, 2009, 9:17:45 PM6/6/09
to pylons-devel
Hey guy, today I threw together this little function helper that I
miss a lot in WebHelpers.

unidecode module can be obtained from
http://code.zemanta.com/tsolc/unidecode/releases/Unidecode-0.04.1.tar.gz


source: http://paste.pocoo.org/show/121523/

Mike Orr

unread,
Jun 11, 2009, 6:10:28 PM6/11/09
to pylons...@googlegroups.com

Hmm, Unidecode is 1.4 MB, which is bigger than WebHelpers. What are
you using the slugs for? What general purpose would they have in
other sites?

--
Mike Orr <slugg...@gmail.com>

iElectric

unread,
Jun 11, 2009, 7:01:02 PM6/11/09
to pylons...@googlegroups.com
Unidecode maps every unicode character to a ASCII char. That's why it's
so big. Slugs are used for url generation that is SEO friendly and self
explainatory. Most cases are blog entries mapped to URLs. Having
numerical ids in URLs to map resources has many cons.

I could ask the unidecode author to release package on pypi and
WebHelpers users would require them by need basis.

Jonathan Vanasco

unread,
Jun 17, 2009, 12:17:01 PM6/17/09
to pylons-devel
oh neat!

at first i thought this was for some sort of preview text, then
realized it was for a url friendly marker

i do something a little different.

also, i'd check to make sure what you get the url chars from. last i
checked, most things in python, perl, etc were written to rfc 1738 or
2396 but rfc 3986 was the current.

anyways, i have a url encoding module as such:

http://paste.pocoo.org/show/QOLc8c6FD7Mqvyu28lSg/

which references some functions in a Misc package

http://paste.pocoo.org/show/123669/

then i call it through:

( standardized, stripped, metaphoned ) = string_to_webtitle_data
( string )

which gives me the slug, a nice text display version, and a metaphone
encoding.

it's less useful for social-bookmarking and more useful for creating
'dictionary' or 'phonebook' style directories

iElectric

unread,
Jun 17, 2009, 12:31:56 PM6/17/09
to pylons...@googlegroups.com
That's how I aproached this before but I hate it strips non ASCII chars.
Good point, I changed code a bit:

http://paste.pocoo.org/show/123671/

Ben Bangert

unread,
Jun 18, 2009, 3:48:28 PM6/18/09
to pylons...@googlegroups.com
On Jun 6, 2009, at 6:17 PM, Domen Kožar wrote:

> Hey guy, today I threw together this little function helper that I
> miss a lot in WebHelpers.
>
> unidecode module can be obtained from
> http://code.zemanta.com/tsolc/unidecode/releases/Unidecode-0.04.1.tar.gz

Funny, as I was porting my blog from a Rails-based Typo one, to Pylons
+ MongoDB, I needed a slug generator. The Rails one used a package
called stringex which is quite handy for other common slug
conversions, and I posted Unideocde to Cheeseshop so its
easy_installable. Here's my slugger (urlify), that is ported from the
Ruby version, which also uses unidecode in addition to other common
replacements for a slug:
http://bitbucket.org/bbangert/minger/src/tip/minger/lib/stringex.py

It would be handy to perhaps have those functions in WebHelpers, with
an optional dependency on Unidecode to use it when available?

Cheers,
Ben

Isaac Csandl

unread,
Jul 24, 2009, 1:36:17 PM7/24/09
to pylons-devel
On Jun 18, 2:48 pm, Ben Bangert <b...@groovie.org> wrote:
> It would be handy to perhaps have those functions in WebHelpers, with  
> an optional dependency on Unidecode to use it when available?

+1 to that.

Mike Orr

unread,
Jul 24, 2009, 2:30:13 PM7/24/09
to pylons...@googlegroups.com

It's in WebHelpers dev already. (Finally I have my own time machine!)
webhelpers.text.urlify(). There's also a companion
remove_formatting() to strip HTML tags, and some character/entity
converters. All by Ben and based on Ruby's stringex package.

--
Mike Orr <slugg...@gmail.com>

Reply all
Reply to author
Forward
0 new messages