# 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 end def name @name end def uri $person_uris[@name] end def email $person_emails[@name] end def html if not email.nil? return "#{name}" elsif not uri.nil? return "#{name}" else return @name end end def atom ret = "" ret += "#{name}" unless name.nil? ret += "#{uri}" unless uri.nil? ret += "#{email}" unless email.nil? end end class License def initialize(name) @name = name end def name @name end def url $license_urls[@name] end def html "#{name}" 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 = "

The content of this page is Copyright © #{@date.year unless @date.nil?} #{@author.html}.

\n" + "

This page is licensed under the #{@license.html} license.

" @breadcrumbs = 'Luke Shumaker » ' if (@slug == 'index') @breadcrumbs += "blog" else @breadcrumbs += 'blog » ' + @slug end end end def html_escape(html) html .gsub('&', '&') .gsub('>', '>') .gsub('<', '<') end