diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-12-31 22:48:59 -0700 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-12-31 22:48:59 -0700 |
commit | b864379651d4bfe3d05f98350b720794ffa2806a (patch) | |
tree | c4bc81a8371694d661b10118b4932480aaa37d0b /bin/util.rb | |
parent | 7445ea9d56071cfca247689e22c6fded65c3f968 (diff) |
more
Diffstat (limited to 'bin/util.rb')
-rw-r--r-- | bin/util.rb | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/bin/util.rb b/bin/util.rb index d95ddba..ec604a3 100644 --- a/bin/util.rb +++ b/bin/util.rb @@ -2,6 +2,7 @@ load 'pandoc.rb' require 'erb' require 'date' +require 'set' $license_urls = { "CC BY-SA-3.0" => 'https://creativecommons.org/licenses/by-sa/3.0/', @@ -86,15 +87,49 @@ class Page end def title ; @title ||= pandoc['title'] || input.split("\n",2).first ; end + def showtitle ; @showtitle ||= ! pandoc['title'].nil? ; end + def author ; @author ||= Person.new( pandoc['author'] || "Andrew Murrell") ; end def license ; @license ||= License.new(pandoc['license'] || "CC BY-SA-3.0") ; end - def date ; @date ||= Date.parse(pandoc['date']) unless pandoc['date'].nil? ; end def slug ; @slug ||= infile.sub(/\..*$/,'').sub(/^.*\//,'') ; end def content ; @content ||= pandoc.to('html5 '+(pandoc['pandoc_flags']||'')) ; end def head ; @head ||= pandoc['html_head_extra'] ; end + def tags ; @tags ||= (pandoc['tags'] || '').split ; end + + def published + if @published.nil? + raw = pandoc['published'] + @published = Date.parse(raw) unless raw.nil? + end + if @published.nil? + raw = `git log -n1 --reverse --format='%cI' -- #{infile}` + @published = DateTime.iso8601(raw) unless raw.empty? + if !updated.nil? && updated < @published + @published = updated + end + 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 + @updated + end def rights - @rights ||= "<p>The content of this page is Copyright © #{date.year unless date.nil?} #{author.html}.</p>\n" + + years = `git log --date=format:'%Y' --format='%cd' -- .config/login.sh`.split('\n').map{|s|s.to_i} + years.unshift(published.year) unless published.nil? + years.unshift(updated.year) unless updated.nil? + years = Set[*years] + # TODO: simplify year spans + @rights ||= "<p>The content of this page is Copyright © #{years.sort.join(', ')} #{author.html}.</p>\n" + "<p>This page is licensed under the #{license.html} license.</p>" end |