From 735f76e124ea65ca5706f1feedc0043b913f11c3 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Tue, 3 Jan 2017 21:26:57 -0500 Subject: Implement external resources. --- bin/index | 6 +++- bin/index.atom.erb | 4 ++- bin/util.rb | 103 +++++++++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 97 insertions(+), 16 deletions(-) (limited to 'bin') 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 @@ <%= page.updated.rfc3339 %> <%= page.published.rfc3339 %> <%= page.title %> - <%= html_escape(page.content) %> <%= page.author.atom %> +<% if page.content %> + <%= html_escape(page.content) %> <%= html_escape(page.rights) %> +<% end %> <% end %> 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('>', '>') .gsub('<', '<') 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 -- cgit v1.2.3-54-g00ecf