permalink_fu has been great to create a Search Engine Optimized (SEO) friendly URL, but I was a bit irritated when the-permalink-is-getting-too-long-with-too-many-unecessary-keywords.

From some of the SEO tips I read, it is advisable not too put too many keywords in the URL. Unecessary stop words such as ‘the, a, in, on, and the list goes on’ can be removed, and the search engine robots will not be irritated too.

I wrote permalink_fu_hack plugin some time ago to solve this problem, thought some of you may find it useful in your application. To think about all the possible stop words, I took the shortcut, and got the inspiration from SEO Slugs Wordpress plugin by Andrei Mikrukov.

It is a monkey patch for permalink_fu, you need to first install the permalink_fu plugin. It also has an additonal :unique option to turn off the feature to automatically create unique permalink, which on some cases where the permalink already includes a unique primary key id, I find that the extra check is not necessary. With the :unique option, you can set it to false for such occasion.

Installation

  script/plugin install git://github.com/technoweenie/permalink_fu.git
  script/plugin install git://github.com/jugend/permalink_fu_hack.git

Example

  class Article < ActiveRecord::Base
    has_permalink :title, :filter_stop_words => true,
        :unique => false
  end

  article = Article.new
  article.title = 'The Permalink Is Getting Too Long With Too Many Unecessary Keywords'
  article.save
  puts article.permalink     # => 'permalink-getting-long-unecessary-keywords'

Additional has_permalink Options

  :unique               
     # Create unique permalink (default: true).
  :filter_stop_words 
     # Flag to filter to stop words (default: false)
  :stop_words         
     # Array of stop words to filter (default: auto assigned to stop words similar to SEO Slugs Wordpress Plugin).
  :max_words         
     # Maximum number of words to show on permalink (default: 6)

3 Comments . Comments Feed . Trackback URI
Tue, 19 Aug 08 04:54 pm . Andy Croll wrote:

Had you thought about using the set of small words from http://daringfireball.net/2008/08/title_case_update as the default?

Sun, 24 Aug 08 01:17 am . Thibaut wrote:

That’s a clever idea, thanks for sharing!

For those who need to transform accents (like éêè) to the corresponding letter without accent, check out the diacritics_fu library: http://github.com/thbar/diacritics_fu/tree/master

cheers

Mon, 25 Aug 08 10:23 am . Herryanto Siatono wrote:

@Andy That’s pretty decent set of of stop words, but think it’s not exhaustive enough, anyway, we can always replace it with our preferred stop_words option depending on our need.

@Thibaut Thanks for the note on diacritics_fu.:

Add Your Comment



(optional)