Генериране на Google, Yahoo sitemap.xml в rails сайт

Динамично генериране на sitemap.xml в ruby on rails сайт

controller:

def sitemap
  @posts = Post.find :all
  render :layout => false
end

view:

xml.instruct!
xml.urlset "xmlns" => "http://www.sitemaps.org/schemas/sitemap/0.9" do
  xml.url do
    xml.loc         "http://www.YourSite.com/"
    xml.lastmod     w3c_date(Time.now)
    xml.changefreq  "always"
  end
  @posts.each do |post|
    xml.url do
      xml.loc         url_for(:only_path => false, :controller => 'home', :action => 'details', :id => post)
      xml.lastmod     w3c_date(post.created_at)
      xml.changefreq  "weekly"
      xml.priority    0.9
    end
  end
end

helper:

def w3c_date(date)
  date.utc.strftime("%Y-%m-%dT%H:%M:%S+00:00")
end

routes:

#Sitemap
map.connect "sitemap.xml", :controller => "home", :action => "sitemap"

Добавете Вашият sitemap в Google http://www.google.com/webmasters/sitemap

This entry was posted on вторник, февруари 12th, 2008 at 1:14 am and is filed under Полезно. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Няма коментари

Be the first to comment on this entry.

Have your say

Fields in bold are required. Email addresses are never published or distributed.

Some HTML code is allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>
URIs must be fully qualified (eg: http://www.domainname.com) and all tags must be properly closed.

Line breaks and paragraphs are automatically converted.

Please keep comments relevant. Off-topic, offensive or inappropriate comments may be edited or removed.

  1. Add to Technorati Favorites View Jivko Georgiev's profile on LinkedIn Add to Google Reader or Homepage      Sub
scribe in NewsGator Online  Add to netvibes
  2. Скорошни публикации

  3. Категории

  4. Страници

  5. Тагове

  6. Архиви

  7. Календар

    февруари 2008
    П В С Ч П С Н
        мар »
     123
    45678910
    11121314151617
    18192021222324
    2526272829  
  8. RSS ShareSnippets: jivko

  9. RSS del.icio.us/jommy

  10. .

  11. Spam Blocked