Wrap text
blogify.rake
|
|
%w(rubygems rake erb atom/collection).each { |l| require l }
store_path = ENV['STORE_PATH'] || File.dirname(__FILE__) + '/atom-store'
pub_path = ENV['PUB_PATH'] || File.dirname(__FILE__)
collection_path = File.join(store_path, 'collection.atom')
template = ERB.new( File.read(__FILE__).gsub(/.*__END__\n/m, '') )
collection = Atom::Collection.parse( File.open(collection_path).read )
monthly_entries = {}
collection.entries.each do |entry|
month = "#{entry.updated.year}/#{entry.updated.month}"
monthly_entries[month] = [] unless monthly_entries.has_key?(month)
monthly_entries[month] << entry
end
def build_link(rel, href)
link = Atom::Link.new
link['rel'] = rel
link['href'] = href
link
end
namespace :blog do
desc 'Generate the HTML files'
task :html do
monthly_entries.each_pair do |month, entries|
directory(month)
File.open( File.join(pub_path, month+'.html'), 'w') { |f| f << template.result(binding) }
end
end
desc 'Create index.html'
task :index => :html do
cp File.join(pub_path, monthly_entries.keys.sort.pop+'.html'), File.join(pub_path, 'index.html')
end
desc 'Generate the Atom feed'
task :feed do
collection.id = 'http://omnifaria.com/index.atom'
collection.base = 'http://omnifaria.com'
collection.updated = Time.now
collection.links << build_link('self', 'http://omnifaria.com')
author = collection.authors.new
author.name = 'Simon Rozet'
author.email = 'simon@rozet.name'
author.uri = 'http://purl.org/net/sr/'
collection.entries.each do |entry|
id = entry.edit_url =~ /([a-z0-9]*)\.atom/i && $1
entry.links[0]['href'] = "/#{entry.updated.year}/#{entry.updated.month}.html##{id}"
entry.links[0]['rel'] = 'alternate'
entry.links[0]['type'] = 'text/html'
end
File.open(File.join(pub_path, 'index.atom'), 'w') { |f| f << collection.to_s }
end
desc 'Generate your weblog'
task :generate => [:html, :index, :feed]
end
__END__
Omnifaria (<%= entries[0].updated.year %>-<%= entries[0].updated.month %>)
Omnifaria
Parution sporadique de billets principalement à propos du Web (sémantique).
<% entries.each do |entry| %>
<% post_id = entry.edit_url =~ /\/\d\d\d\d\/\d\d\/\d\d\/([0-9A-Za-z\-]+)\.atom$/ && $1 %>
<%= entry.title %>
<%= entry.content %>
Published on "><%= entry.updated.strftime("%Y-%m-%d") %>
<% end %>
|