rails 下生成 sitemap

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
 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值