= Sitemapper - Easy SEO engine
Sitemapper will help you in various SEO techniques such as sitemap.xml
auto generation.
== Installation
You can install the development version with
% sudo gem install milk-it-sitemapper -s http://gems.github.com
Or the release version with
% sudo gem install sitemapper
== Examples
=== Ruby On Rails
Sitemapper will automagically generate a sitemap.xml file for you when
your rails application start, this sitemap.xml will include all your
URLs that Sitemapper consider 'static', for example:
map.todo '/to-do' # Sitemapper will consider this as static
map.articles '/articles/:year/:month' # Will be considered this dynamic
map.connect '*path' # Will be considered dynamic
The generation of your sitemap.xml will happen on your application boot,
but it won't delete any URL previous added (we hope to be able to do so
very soon - a merge).
In your application, you can use the accessors provided by Sitemapper to
dynamically add URLs, for example, supose a blog app:
class ArticlesController < ApplicationController
...
def create
# do all the creation stuff
map_url(article_url(@article)) # add the URL to your sitemap
end
def destroy
# do all the deletion stuff
unmap_url(article_url(@article))
end
...
end
You can also do it on your sweepers (which is a better choice)
class ArticleSweeper < ActionController::Caching::Sweeper
observe Article, Account
def after_create(record)
# expire everything you need
map_url(polymorphic_url(record))
end
def after_destroy(record)
# expire everything you need
map_url(polymorphic_url(record))
end
end
=== Merb
Sorry, we do not support Merb yet. (Actually, it will depend on the
demand)
=== Mapping multiple URLs
If you need to map multiple urls, it's high recommended to use #map_urls, to do so:
map.map_urls do |map|
map.map_url('http://www.example.org/about')
...
end
or, if you are in a Sweeper or Controller
map_urls do |map|
...
end
=== Other SEO techniques
With SEO, you'll have some view helpers to easily apply some SEO
techniques to your website/webapp.
In your application layout, just do it:
<%= title('My Personal Blog') %>
<%= page_meta %>
And in your action views, you put this:
<% page(:title => 'Contact',
:desc => 'Here you'll can contact our customer support ...',
:keywords => 'contact, support, customer') %>
In this case, the view will be rendered in this way:
Contact :: My Personal Blog
If you want to change the title separator, just do:
...
<%= title('My Personal Blog', :separator => ' - ') %>
...
Or, you can als use any object that respond to title or name (for
page title), short_description or description, tag_list or keywords.
<% page(@event) %>
If you need to change the default method lookup for page, you have two ways:
==== Add an initializer with the following content (that will change the default method lookup sequence):
Sitemapper.meta_lookup = {:title => [:my_default_title_method, :my_second_default_title_method]
:desc => [:my_default_description_method, :my_second_default_description_method],
:keywords => [:my_default_keywords_method, :my_second_default_keywords_methods]
}
==== Configure per object (yes, object, not just ActiveRecord descendents) lookups:
class MyObject
map_fields :title => :weird_title, :desc => :weird_description, :keywords => :weird_keywords
...
end
If you don't specify all the fields, it'll be merged with the Sitemapper.meta_lookup config.
=== Hope you enjoy!
If you want to suggest any other SEO technique, suggest it on carlos@milk-it.net
== To do:
- Add sitemap options to routes
- Create separate files for dynamic and static routes (then, we'll can
delete all the static on startup)
- Write test code (sorry, I really didn't it)
Copyright (c) 2008 Carlos Júnior, released under the MIT license
Copyright (c) 2008 Milk-it Software House, released under the MIT license