google了一下,找了一个sitemap 的插件,还比较好用,拿出来大家分享一下
插件地址:http://aktagon.com/projects/rails/sitemap-generator
Install
$ script/plugin install git://github.com/christianhellsten/sitemap-generator.git
Config
装完后会在config目录里生成sitemap.yml文件,但是我装完之后没有,不过没关系自己建一个就好了。配置就抄网站上的啦:
domain: aktagon.com limit: 5000 priority: 1 change_frequency: weekly
说明:
- domain: before using the sitemap generator you need to tell the plugin the domain where your application is deployed. This is because the sitemap must contain the full URL , not just the URI , of all resources.
- limit: specifies how many model instances you want to include in the sitemap
- priority: specifies the priority of the model
- change_frequency: specifies how often the data changes: always, hourly, daily, weekly, monthly, yearly or never
Configuring ActiveRecord
在你希望收录到sitemap里的 ActiveRecord里加上相关方法:
class Post < ActiveRecord::Base
sitemap :change_frequency => :daily, :limit => 5000, :priority => 0.8
end
Usage
配置好后就可以生成了,跑完后在 public目录下就有sitemap.xml了,快去看看。希望每天跑的话可以做一个cronjob。
rake sitemap:generate