Validated Atom and RSS feeds, setup redirects.
h3rald h3rald@h3rald.com
Sat, 29 Aug 2009 20:39:16 +0200
2 files changed,
27 insertions(+),
10 deletions(-)
M
lib/helpers.rb
→
lib/helpers.rb
@@ -33,13 +33,27 @@ end
module Nanoc3::Helpers::Blogging + def reencode_html_entities(string) + require 'htmlentities' + $KCODE = 'u' + coder = HTMLEntities.new + # Change named entities to their unicode counterparts + string.gsub!(/&.+?;/) do |m| + coder.encode(coder.decode(m), :decimal) + end + # Encode & in URLs + string.gsub! /&(.+?)=/, '&\1=' + string + end + def prepare_feed(params) # Extract parameters @item[:limit] ||= 10 @item[:articles] = params[:articles] || latest_articles(10) || [] - @item[:content_proc] = params[:content_proc] || lambda { |a| a.reps[0].content_at_snapshot(:pre)} + @item[:content_proc] = params[:content_proc] || lambda { |a| reencode_html_entities(a.reps[0].content_at_snapshot(:pre))} @item[:excerpt_proc] = params[:excerpt_proc] || lambda { |a| a[:excerpt] } @item[:author_uri] ||= @site.config[:base_url] + @item[:author_name] ||= @site.config[:author_name] raise RuntimeError.new('Cannot build feed: site configuration has no base_url') if @site.config[:base_url].nil? raise RuntimeError.new('Cannot build feed: feed item has no title') if @item[:title].nil? raise RuntimeError.new('Cannot build feed: no articles') if @item[:articles].empty?@@ -101,20 +115,22 @@ xml.author do
xml.name @item[:author_name] xml.uri @item[:author_uri] end + count = 0 @item[:articles].each do |a| xml.entry do xml.id atom_tag_for(a) xml.title a[:title] xml.published a[:date].to_iso8601_time - xml.updated a.mtime.to_iso8601_time + xml.updated (a.mtime-count).to_iso8601_time + count = count+1 xml.link(:rel => 'alternate', :href => url_for(a)) a[:tags].each do |t| xml.category(:term => t, :scheme => "#{@site.config[:base_url]}/tags/#{t}/") end summary = @item[:excerpt_proc].call(a) - xml.summary summary, :type => 'xhtml' unless summary.nil? - xml.content(:type => 'xhtml') do |c| - c << %{<div xmlns="http://www.w3.org/1999/xhtml">\n#{@item[:content_proc].call(a)}\n</div>} + xml.summary summary, :type => 'html' unless summary.nil? + xml.content(:type => 'html') do |c| + c << %{<![CDATA[\n#{@item[:content_proc].call(a)}]]>\n} end end end
M
resources/.htaccess
→
resources/.htaccess
@@ -45,11 +45,12 @@
# Rewrite rules. <IfModule mod_rewrite.c> RewriteEngine on - - RewriteRule ^rss$ /rss.xml - RewriteRule ^atom$ /atom.xml - - RewriteRule ^$ /home/index.html [L,QSA] + RewriteCond %{REQUEST_FILENAME} !-f + RewriteCond %{REQUEST_URI} !(.*)/$ + RewriteRule ^(.+[^/])$ /$1/ [R=301] + RewriteRule ^rss/$ /rss.xml [L] + RewriteRule ^atom/$ /atom.xml [L] + RewriteRule ^$ /home/index.html [L] </IfModule>