summaryrefslogtreecommitdiff
path: root/util.rb
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2016-08-27 19:12:36 -0400
committerLuke Shumaker <lukeshu@sbcglobal.net>2016-08-27 19:12:36 -0400
commit75d4d72a1f5352d1c3520fbaf96911309fc7f96a (patch)
tree942dfa89658964e5954f159fa4d9b41c6b7bc423 /util.rb
parentb373a3a6e1702e7514bb405122a2311d16d85fcd (diff)
index.atom, also: write-atomic
Diffstat (limited to 'util.rb')
-rw-r--r--util.rb47
1 files changed, 47 insertions, 0 deletions
diff --git a/util.rb b/util.rb
index f7bd1b9..e50406a 100644
--- a/util.rb
+++ b/util.rb
@@ -1,3 +1,19 @@
+# coding: utf-8
+load 'pandoc.rb'
+require 'erb'
+require 'date'
+
+$license_urls = {
+ "CC BY-SA-3.0" => 'https://creativecommons.org/licenses/by-sa/3.0/',
+ 'WTFPL-2' => "http://www.wtfpl.net/txt/copying/",
+}
+$person_uris = {
+ "Luke Shumaker" => "https://lukeshu.com/",
+}
+$person_emails = {
+ "Luke Shumaker" => "lukeshu@sbcglobal.net",
+}
+
class Person
def initialize(name)
@name = name
@@ -43,6 +59,37 @@ class License
end
end
+class Page
+ attr_accessor :title, :author, :gitdate, :date, :license, :slug, :content, :rights, :breadcrumbs
+ def initialize(infile)
+ input = File.read(infile)
+ doc = Pandoc::load('markdown', input)
+
+ 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 = Person.new(doc['author'] || "Luke Shumaker")
+ @gitdate = DateTime.iso8601(gitdate) unless gitdate.empty?
+ @date = Date.parse(doc['date']) unless doc['date'].nil?
+ @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 (@slug == 'index')
+ @breadcrumbs += "blog"
+ else
+ @breadcrumbs += '<a href=/blog>blog</a> » ' + @slug
+ end
+ end
+end
+
def html_escape(html)
html
.gsub('&', '&amp;')