summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rwxr-xr-xbin/index6
-rw-r--r--bin/index.atom.erb4
-rw-r--r--bin/util.rb103
3 files changed, 97 insertions, 16 deletions
diff --git a/bin/index b/bin/index
index dc57798..48968a3 100755
--- a/bin/index
+++ b/bin/index
@@ -24,8 +24,12 @@ else
metadata = {}
end
-# ARGV[2..]
@pages = []
+for data in metadata['external']
+ @pages.push(ExternPage.new(data))
+end
+
+# ARGV[2..]
for filename in ARGV do
@pages.push(Page.new(filename))
end
diff --git a/bin/index.atom.erb b/bin/index.atom.erb
index c02f709..5b0ef36 100644
--- a/bin/index.atom.erb
+++ b/bin/index.atom.erb
@@ -16,9 +16,11 @@
<updated><%= page.updated.rfc3339 %></updated>
<published><%= page.published.rfc3339 %></published>
<title><%= page.title %></title>
- <content type="html"><%= html_escape(page.content) %></content>
<author><%= page.author.atom %></author>
+<% if page.content %>
+ <content type="html"><%= html_escape(page.content) %></content>
<rights type="html"><%= html_escape(page.rights) %></rights>
+<% end %>
</entry>
<% end %>
</feed>
diff --git a/bin/util.rb b/bin/util.rb
index 2cfc63e..b2dcd40 100644
--- a/bin/util.rb
+++ b/bin/util.rb
@@ -133,18 +133,44 @@ class Page
@tags
end
- def published
- if @published.nil?
+ def _published
+ if @_published.nil?
raw = pandoc['published']
- @published = Date.parse(raw) unless raw.nil?
+ @_published = Date.parse(raw) unless raw.nil?
end
- if @published.nil?
+ if @_published.nil?
raw = `git log -n1 --reverse --format='%cI' -- #{infile}`
- @published = DateTime.iso8601(raw) unless raw.empty?
+ @_published = DateTime.iso8601(raw) unless raw.empty?
+ end
+ @_published
+ end
+
+ def _updated
+ if @_updated.nil?
+ raw = pandoc['updated']
+ @_updated = Date.parse(raw) unless raw.nil?
+ end
+ if @_updated.nil?
+ raw = `git log -n1 --format='%cI' -- #{infile}`
+ @_updated = DateTime.iso8601(raw) unless raw.empty?
end
- unless @published.nil? or updated.nil?
- if updated < @published
- @published = updated
+ @_updated
+ end
+
+ def published
+ if @published.nil?
+ unless _published.nil?
+ @published = _published
+ else
+ unless _updated.nil?
+ @published = _updated
+ end
+ end
+ # sanity check
+ unless _published.nil? or _updated.nil?
+ if _updated < _published
+ @published = _updated
+ end
end
end
@published
@@ -152,12 +178,13 @@ class Page
def updated
if @updated.nil?
- raw = pandoc['updated']
- @updated = Date.parse(raw) unless raw.nil?
- end
- if @updated.nil?
- raw = `git log -n1 --format='%cI' -- #{infile}`
- @updated = DateTime.iso8601(raw) unless raw.empty?
+ unless _updated.nil?
+ @updated = _updated
+ else
+ unless _published.nil?
+ @updated = _published
+ end
+ end
end
@updated
end
@@ -217,3 +244,51 @@ def html_escape(html)
.gsub('>', '&gt;')
.gsub('<', '&lt;')
end
+
+class ExternPage
+ def initialize(metadata)
+ @metadata = metadata
+ end
+
+ def title
+ @metadata['title']
+ end
+
+ def content
+ nil
+ end
+
+ def tags
+ if @tags.nil?
+ raw = @metadata['tags'] || []
+ if raw.is_a?(String)
+ raw = raw.split
+ end
+ @tags = raw.map{|tag|Tag.new(tag)}
+ end
+ return @tags
+ end
+
+ def url
+ return $url + @metadata['url']
+ end
+
+ def author
+ Person.new(@metadata['author'] || "Andrew Murrell")
+ end
+
+ def published
+ str = @metadata['published']
+ if str.nil? and ! @metadata['updated'].nil?
+ str = @metadata['updated']
+ end
+ return Date.parse(str)
+ end
+ def updated
+ str = @metadata['updated']
+ if str.nil? and ! @metadata['published'].nil?
+ str = @metadata['published']
+ end
+ return Date.parse(str)
+ end
+end