Implemented tag feed generation. * Closes #9.
h3rald h3rald@h3rald.com
Sat, 29 Aug 2009 21:55:25 +0200
123 files changed,
563 insertions(+),
14 deletions(-)
jump to
M
content/atom.xml
→
content/atom.xml
@@ -1,7 +1,6 @@
--- permalink: 'atom' type: 'feed' -title: 'Latest Articles (Atom) - HERALD' -path: '/atom/' +title: 'H3RALD - Articles (Atom Feed)' --- <%= atom_feed %>
M
content/home.textile
→
content/home.textile
@@ -6,6 +6,7 @@ - redcloth
title: Home type: page feed: '/' +feed_title: 'Latest Articles' ----- <% max_items = 5
M
content/rss.xml
→
content/rss.xml
@@ -1,7 +1,6 @@
--- permalink: 'rss' type: 'feed' -title: 'Latest Articles (RSS) - HERALD' -path: '/rss/' +title: 'H3RALD - Articles (RSS Feed)' --- <%= rss_feed %>
M
layouts/default.htm
→
layouts/default.htm
@@ -7,8 +7,8 @@ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head> <title><%= @item[:title] %> - H3RALD</title> <% if @item[:feed] then %> - <link rel="alternate" type="application/rss+xml" title="RSS" href="<%= @item[:feed]%>rss/" /> - <link rel="alternate" type="application/atom+xml" title="ATOM" href="<%= @item[:feed]%>atom/" /> + <link rel="alternate" type="application/rss+xml" title="H3RALD - <%= @item[:feed_title]%> (RSS Feed)" href="<%= @item[:feed]%>rss/" /> + <link rel="alternate" type="application/atom+xml" title="H3RALD - <%= @item[:feed_title]%> (Atom Feed)" href="<%= @item[:feed]%>atom/" /> <% end %> <meta name="author" content="Fabio Cevasco" /> <meta name="copyright" content="Fabio Cevasco" />
M
lib/helpers.rb
→
lib/helpers.rb
@@ -34,6 +34,7 @@
module Nanoc3::Helpers::Blogging def reencode_html_entities(string) +=begin require 'htmlentities' $KCODE = 'u' coder = HTMLEntities.new@@ -43,6 +44,7 @@ coder.encode(coder.decode(m), :decimal)
end # Encode & in URLs string.gsub! /&(.+?)=/, '&\1=' +=end string end@@ -110,7 +112,7 @@ xml.id @site.config[:base_url] + '/'
xml.title @item[:title] xml.updated @item[:last][:date].to_iso8601_time xml.link(:rel => 'alternate', :href => @site.config[:base_url]) - xml.link(:rel => 'self', :href => @site.config[:base_url]+@item[:path]) + xml.link(:rel => 'self', :href => @site.config[:base_url]+"/#{@item[:permalink]}/") xml.author do xml.name @item[:author_name] xml.uri @item[:author_uri]@@ -121,7 +123,7 @@ xml.entry do
xml.id atom_tag_for(a) xml.title a[:title] xml.published a[:date].to_iso8601_time - xml.updated (a.mtime-count).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|
M
lib/utils.rb
→
lib/utils.rb
@@ -1,11 +1,12 @@
module SiteUtils def write_tag_page(dir, tag, count) - # Create tag page meta = {} meta[:title] = "Tag: #{tag}" meta[:type] = 'page' meta[:filters_pre] = ['erb', 'redcloth'] + meta[:feed] = "/tags/#{tag}/" + meta[:feed_title] = "Tag '#{tag}'" meta[:permalink] = tag pl = (count == 1) ? ' is' : 's are' contents = %{\n#{count} item#{pl} tagged with _#{tag}_:@@ -18,8 +19,17 @@ # Write html page
write_item dir/"#{tag}.textile", meta, contents end + def write_tag_feed_page(dir, tag, format) + f = format.downcase + meta = {} + meta[:title] = "H3RALD - Tag '#{tag}' (#{format} Feed)" + meta[:type] = 'feed' + meta[:permalink] = "tags/#{tag}/#{f}" + contents = %{<%= #{f}_feed(:articles => articles_tagged_with('#{tag}'))%>} + write_item dir/"#{tag}-#{f}.xml", meta, contents + end + def write_archive_page(dir, name, count) - # Create archive page meta = {} meta[:title] = "Archive: #{name}" meta[:type] = 'page'
M
resources/.htaccess
→
resources/.htaccess
@@ -48,8 +48,8 @@ RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} !(.*)/$ RewriteRule ^(.+[^/])$ /$1/ [R=301] - RewriteRule ^rss/$ /rss.xml [L] - RewriteRule ^atom/$ /atom.xml [L] + RewriteRule ^(rss|atom)/$ /$1.xml [L] + RewriteRule ^tags/(.+)/(rss|atom)/$ /tags/$1/$2.xml [L] RewriteRule ^$ /home/index.html [L] </IfModule>
M
tasks/site.rake
→
tasks/site.rake
@@ -9,7 +9,7 @@ include SiteUtils
namespace :site do - task :clear_output do + task :clean do output = Pathname.new(Dir.pwd)/'output' puts "Deleting all files in output dir..." output.rmtree@@ -24,7 +24,7 @@ task :run => [:copy_resources] do
system "nanoc3 aco -s thin" end - task :rebuild => [:clear_output, :update] do + task :rebuild => [:clean, :update] do end task :tags do@@ -48,6 +48,8 @@ end
# Write pages tags.each_pair do |k, v| write_tag_page dir, k, v + write_tag_feed_page dir, k, 'RSS' + write_tag_feed_page dir, k, 'Atom' end end