Permalink
Browse files

Generate Atom feed, and link to it from pages.

  • Loading branch information...
1 parent fb5fca0 commit 1186956039ed80da0966d2302b1f22a7db64d778 @runpaint committed May 13, 2009
Showing with 57 additions and 4 deletions.
  1. +16 −4 Rakefile
  2. +33 −0 templates/atom.atom
  3. +2 −0 templates/chapter.html
  4. +2 −0 templates/recipe.html
  5. +2 −0 templates/toc.html
  6. +2 −0 www/index.html
View
@@ -44,6 +44,11 @@ task :sitemap_notify do
sh "sitemap_gen.py --config=sitemap_config.xml"
end
+def commit_time(file)
+ Time.at(`git log -r --name-only --no-color --pretty=raw -z #{file}`.
+ to_a.grep(/^committer/).last.match(/ (\d+) /)[1].to_i)
+end
+
def make_toc
toc = []
section = 'Preliminaries'
@@ -53,7 +58,7 @@ def make_toc
doc = Hpricot(source)
recipe_id = nil
doc.search('h1, h2, h3, h4, h5, h6').each do |h_tag|
- title = h_tag ? h_tag.inner_html : 'Untitled'
+ title = h_tag ? h_tag.inner_text : 'Untitled'
id = h_tag['id'] if h_tag
next unless id && h_tag
type = :subsection
@@ -65,9 +70,10 @@ def make_toc
type = :recipe
recipe_id = h_tag['id']
end
- toc << { :id => h_tag['id'], :title => h_tag.inner_html, :file => f,
+ toc << { :id => h_tag['id'], :title => title, :file => f,
:type => type, :section_name => section, :section_id => section_id,
- :recipe_id => recipe_id }
+ :recipe_id => recipe_id, :time => commit_time(f),
+ :target_path => "output/#{section_id}/#{h_tag['id']}/index.html" }
end
end
toc
@@ -130,16 +136,22 @@ task :html => SOURCE_HTML do |t|
{:body => doc.to_s, :title => entry[:title], :id => entry[:id],
:section_id => entry[:section_id], :section => entry[:section_name],
:next_e => nxt, :prev_e => prv})
-
+ #FIXME: Use :target_path instead:
path = "output/#{entry[:section_id]}/#{entry[:id]}/index.html"
mkdir_p File.dirname(path)
File.open(path,'w') {|file| file.puts page}
+ entry[:body] = doc.to_s
end
end
page = Erubis::Eruby.new(File.open('templates/toc.html').read).
result({:toc => toc.dup.reject{|e| e[:type] == :subsection}})
mkdir_p 'output/toc'
File.open('output/toc/index.html','w') {|file| file.puts page}
+ page = Erubis::Eruby.new(File.open('templates/atom.atom').read).
+ result({:toc => toc.
+ reject{|e| e[:type] == :subsection}.sort_by{|e| e[:time]}.reverse
+ })
+ File.open('output/index.atom','w') {|file| file.puts page}
end
directory 'output/css'
View
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="utf-8"?>
+<feed xmlns="http://www.w3.org/2005/Atom"
+ xmlns:thr="http://purl.org/syndication/thread/1.0">
+ <link rel="self" href="http://vim.runpaint.org/index.atom"/>
+ <id>http://vim.runpaint.org/index.atom</id>
+
+ <title>Vim Recipes</title>
+ <subtitle>A cookbook for the Vim text editor</subtitle>
+ <author>
+ <name>Run Paint Run Run</name>
+ <email>runrun@runpaint.org</email>
+ <uri>http://runpaint.org/</uri>
+ </author>
+ <updated>2009-05-13T08:42:22-04:00</updated> <!-- FIXME -->
+ <link href="http://vim.runpaint.org/"/>
+ <link rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/"/>
+
+ <%
+ require 'time'
+ toc.each do |entry|
+ next unless entry[:type] == :recipe
+ %>
+ <entry>
+ <id>tag:vim.runpaint.org,2009:<%= entry[:id] %></id>
+ <link href="/<%= entry[:section_id] %>/<%= entry[:id] %>/"/>
+ <title><%= entry[:title] %></title>
+ <updated><%= entry[:time].xmlschema %></updated>
+ <content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml">
+ <%= entry[:body] %>
+ </div></content>
+ </entry>
+ <% end %>
+</feed>
View
@@ -2,6 +2,8 @@
<head>
<title>Vim Recipes: <%= title %></title>
<link rel="stylesheet" type="text/css" href="/css/style.css"/>
+ <link rel="alternate" type="application/atom+xml" title="Recipes Atom feed"
+ href="/index.atom"/>
</head>
<body>
<form action="http://www.google.com/cse">
View
@@ -2,6 +2,8 @@
<head>
<title>Vim Recipes: <%= title %></title>
<link rel="stylesheet" type="text/css" href="/css/style.css"/>
+ <link rel="alternate" type="application/atom+xml" title="Recipes Atom feed"
+ href="/index.atom"/>
</head>
<body>
<form action="http://www.google.com/cse">
View
@@ -2,6 +2,8 @@
<head>
<title>Vim Recipes: Table of Contents</title>
<link rel="stylesheet" type="text/css" href="/css/style.css"/>
+ <link rel="alternate" type="application/atom+xml" title="Recipes Atom feed"
+ href="/index.atom"/>
</head>
<body>
<form action="http://www.google.com/cse">
View
@@ -2,6 +2,8 @@
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="/css/style.css"/>
+ <link rel="alternate" type="application/atom+xml" title="Recipes Atom feed"
+ href="/index.atom"/>
<title>Vim Recipes - Free cookbook for the Vim text editor</title>
</head>
<body>

0 comments on commit 1186956

Please sign in to comment.