# coding: utf-8 load 'pandoc.rb' require 'erb' require 'date' $license_urls = { "CC BY-SA 4.0" => 'https://creativecommons.org/licenses/by-sa/4.0/', 'WTFPL-2' => "http://www.wtfpl.net/txt/copying/", } $person_uris = { "Luke T. Shumaker" => "https://lukeshu.com/", } $person_emails = { "Luke T. Shumaker" => "lukeshu@lukeshu.com", } 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 def initialize(infile) @infile = infile end def infile ; @infile ; end def input ; @input ||= File.read(infile) ; end def pandoc if @pandoc.nil? @pandoc = Pandoc::load('markdown', input) if @pandoc['markdown_options'] @pandoc = Pandoc::load('markdown'+@pandoc['markdown_options'], input) end end @pandoc end def title ; @title ||= pandoc['title'] || input.split("\n",2).first ; end def author ; @author ||= Person.new( pandoc['author'] || "Luke T. Shumaker") ; end def license ; @license ||= License.new(pandoc['license'] || "CC BY-SA 4.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') ; end def rights @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.

" end def breadcrumbs @breadcrumbs ||= 'Luke T. Shumaker » ' + ( (slug == 'index') ? "blog" : "blog » #{slug}" ) end end def html_escape(html) html .gsub('&', '&') .gsub('>', '>') .gsub('<', '<') end