summaryrefslogtreecommitdiff
path: root/pagerender.rb
diff options
context:
space:
mode:
Diffstat (limited to 'pagerender.rb')
-rwxr-xr-xpagerender.rb39
1 files changed, 20 insertions, 19 deletions
diff --git a/pagerender.rb b/pagerender.rb
index 67c5aab..3c122bc 100755
--- a/pagerender.rb
+++ b/pagerender.rb
@@ -1,21 +1,23 @@
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
load 'pandoc.rb'
+load 'util.rb'
require 'erb'
require 'date'
-license_urls = {
+$license_urls = {
"CC BY-SA-3.0" => 'https://creativecommons.org/licenses/by-sa/3.0/',
'WTFPL-2' => "http://www.wtfpl.net/txt/copying/",
}
-author_urls = {
- "Luke Shumaker" => "mailto:lukeshu@sbcglobal.net",
+$person_uris = {
+ "Luke Shumaker" => "https://lukeshu.com/",
+}
+$person_emails = {
+ "Luke Shumaker" => "lukeshu@sbcglobal.net",
}
-template = 'template.erb'
-infile = ARGV.first
-
-Pandoc::prog='pandoc'
+template = "template.#{ARGV[0]}.erb"
+infile = ARGV[1]
input = File.read(infile)
doc = Pandoc::load('markdown', input)
@@ -24,26 +26,25 @@ if doc['markdown_options']
doc = Pandoc::load('markdown'+doc['markdown_options'], input)
end
+gitdate = `git log -n1 --format='%cI' -- #{infile}`
+
@title = doc['title'] || input.split("\n",2).first
-@author = doc['author'] || "Luke Shumaker"
+@author = Person.new(doc['author'] || "Luke Shumaker")
+@gitdate = DateTime.iso8601(gitdate) unless gitdate.empty?
@date = Date.parse(doc['date']) unless doc['date'].nil?
-@license = doc['license'] || "CC BY-SA-3.0"
-unless license_urls[@license].nil?
- @license="<a href=\"#{license_urls[@license]}\">#{@license}</a>"
-end
-unless author_urls[@author].nil?
- @author="<a href=\"#{author_urls[@author]}\">#{@author}</a>"
-end
+@license = License.new(doc['license'] || "CC BY-SA-3.0")
+@slug = infile.sub(/\..*$/,'').sub(/^.*\//,'')
+@content = doc.to('html5')
+@rights = "<p>The content of this page is Copyright © #{@date.year unless @date.nil?} #{@author.html}.</p>\n" +
+ "<p>This page is licensed under the #{@license.html} license.</p>"
@breadcrumbs = '<a href="/">Luke Shumaker</a> » '
-if (infile =~ /.*\/index(\..*)?/)
+if (@slug == 'index')
@breadcrumbs += "blog"
else
- @breadcrumbs += '<a href=/blog>blog</a> » ' + infile.sub(/\..*$/,'').sub(/^.*\//,'')
+ @breadcrumbs += '<a href=/blog>blog</a> » ' + @slug
end
-@content = doc.to('html5')
-
erb = ERB.new(File.read(template));
erb.filename = template
erb.run()