2

为 Octopress 添加多个 Atom 地址

 2 years ago
source link: https://blog.yxwang.me/2012/12/multiple-feeds-in-octopress/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

为 Octopress 添加多个 Atom 地址

Mon, Dec 31, 2012 • Meta

博客最早用的是 wordpress,首页上提供的 Atom 源是 /feed/。迁移到 Octopress 后,Atom 源地址变成了 /atom.xml。在 Google Reader 里看到订阅 /feed/ 的读者还是有不少的,用默认的地址这些读者就收不到博客更新了。

一个方法是改服务器的配置文件,以我之前使用的 nginx 为例,在相应站点的配置中增加一项 /feed/,把所有对它的访问重定向到 /atom.xml 即可:

location = /feed/ {
    rewrite ^(.*)$ http://blog.yxwang.me/atom.xml;
}

如果服务器支持 .htaccess 也可以用类似的 rewrite 方法重定向。

后来服务器转移到了一个静态空间,不支持 .htaccess,我也没有访问 nginx 配置的权限,只能想办法自己改 Octopress,让它生成两份 Atom 文件。我想到的比较简单的方法是在 Rakefile 的 generate 任务结束后,把生成 atom.xml 复制一份为 /feed/index.html,这样访问 /feed/ 也就能访问到最新的 atom.xml 了:

desc "Generate jekyll site"
task :generate do
  raise "### You haven't set anything up yet. First run `rake install` to set up an Octopress theme." unless File.directory?(source_dir)
  puts "## Generating Site with Jekyll"
  system "compass compile --css-dir #{source_dir}/stylesheets"
  Rake::Task['minify_and_combine'].execute
  system "jekyll"
  system "mkdir -p #{public_dir}/feed"
  system "cp #{public_dir}/atom.xml #{public_dir}/feed/index.html"
end
本作品采用知识共享署名-非商业性使用 3.0 版本许可协议进行许可,欢迎转载,演绎,但是必须保留本文的署名 zellux(包含链接),且不得用于商业目的。

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK