summaryrefslogtreecommitdiff
path: root/bin/util.rb
diff options
context:
space:
mode:
Diffstat (limited to 'bin/util.rb')
-rw-r--r--bin/util.rb103
1 files changed, 89 insertions, 14 deletions
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