diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2017-01-06 19:50:45 -0500 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2017-01-06 19:50:45 -0500 |
commit | 7edb003cd1c9b53ffdff11ef85532e39f08db16d (patch) | |
tree | 180db82a4af7720508ae2732393401bf4d27cadf /bin | |
parent | 7d875df65221d4da91953cf129a03e76fe8e5d29 (diff) |
wip
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/index | 2 | ||||
-rw-r--r-- | bin/index.atom.erb | 26 | ||||
-rw-r--r-- | bin/index.md.erb | 12 | ||||
-rwxr-xr-x | bin/page | 2 | ||||
-rw-r--r-- | bin/page.html.erb | 37 | ||||
-rw-r--r-- | bin/pandoc.rb | 95 | ||||
-rw-r--r-- | bin/util.rb | 302 |
7 files changed, 2 insertions, 474 deletions
@@ -1,6 +1,6 @@ #!/usr/bin/env ruby # -*- coding: utf-8 -*- -load 'util.rb' +require 'util' require 'yaml' # ARGV[0] diff --git a/bin/index.atom.erb b/bin/index.atom.erb deleted file mode 100644 index 5b0ef36..0000000 --- a/bin/index.atom.erb +++ /dev/null @@ -1,26 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<feed xmlns="http://www.w3.org/2005/Atom"> - - <title>AndrewDM.me <%= @title %></title> - <link rel="self" type="application/atom+xml" href="./index.atom"/> - <link rel="alternate" type="text/html" href="./"/> - <link rel="alternate" type="text/markdown" href="./index.md"/> - <updated><%= @pages.map{|p|p.updated}.sort.last.rfc3339 %></updated> - <author><%= Person.new("Andrew Murrell").atom %></author> - <id><%= $url %></id> - - <% @pages.sort_by{|p| p.updated}.reverse.each do |page| %> - <entry xmlns="http://www.w3.org/2005/Atom"> - <link rel="alternate" type="text/html" href="<%= page.url %>"/> - <id><%= page.url %></id> - <updated><%= page.updated.rfc3339 %></updated> - <published><%= page.published.rfc3339 %></published> - <title><%= page.title %></title> - <author><%= page.author.atom %></author> -<% if page.content %> - <content type="html"><%= html_escape(page.content) %></content> - <rights type="html"><%= html_escape(page.rights) %></rights> -<% end %> - </entry> - <% end %> -</feed> diff --git a/bin/index.md.erb b/bin/index.md.erb deleted file mode 100644 index a3ec547..0000000 --- a/bin/index.md.erb +++ /dev/null @@ -1,12 +0,0 @@ ---- -title: "<%= @title %>" -class: "index" ---- - -<% @sections.keys.sort.each do |path| %> -<% unless path.empty? %>## [<%= @sections[path]['head'] %>](<%= path %>)<% end %> - -<% @sections[path]['body'].sort_by{|a|a.published}.reverse.each do |a| %> - * <span><a <% if a.is_a?(ExternPage) %>class="external" <% end %>href="<%= @url.route_to(a.url) %>" title="Published on <%= a.published.strftime('%Y-%m-%d') %><% if a.updated != a.published %> (updated on<%= a.updated.strftime('%Y-%m-%d') %>)<% end %>"><%= a.title %></a></span><span><% a.tags.each do |t| %><%= t.html %><% end %></span><% end %> - -<% end %> @@ -1,6 +1,6 @@ #!/usr/bin/env ruby # -*- coding: utf-8 -*- -load 'util.rb' +require 'util' require 'uri' template = "bin/page.#{ARGV[0]}.erb" diff --git a/bin/page.html.erb b/bin/page.html.erb deleted file mode 100644 index e2dc9fe..0000000 --- a/bin/page.html.erb +++ /dev/null @@ -1,37 +0,0 @@ -<!DOCTYPE html> -<html lang="en"> - <head> - <meta charset="utf-8"> - <title><%= @page.title %><% unless @page.title.empty? %> — <% end %>AndrewDM</title> - <link rel="stylesheet" href="/main.css"> - <link rel="alternate" type="application/atom+xml" href="/index.atom" /> - <%= @page.head %> - </head> - <body<% if @page.class %> class="<%= @page.class %>"<% end %>> - <header> - <h1>AndrewDM</h1> - <nav> - <ul> - <li><a href="/">Projects</a> - <li><a href="/ChangeLog.html"><abbr title="Blog">Blahg</abbr></a> - <li><a href="/Andrew.html">Andrew</a> - <li> - <form method="GET" action="/search.html"> - <input type=search name="s" placeholder="Search" /><input type=submit value="🔍" /> - </form> - </ul> - </nav> - <p class=breadcrumbs><%= @page.breadcrumbs %></p> - </header> - <article> - <% if @page.tags.count > 0 %><p>Tags: <% @page.tags.each do |t| %><%= t.html %><% end %></p><% end %> - <% if @page.showtitle %><h1 class=title><%= @page.title %></h1><% end %> - <%= @page.content %> - </article> - <footer> - <%= @page.rights %> - <p>Page source: <a href="<%= @url.route_to(@page.srcurl) %>"><%= File.basename(@page.srcurl.to_s) %></a></p> - <p>Website source: <a href="https://git.andrewdm.me/www.git">www.git</a></p> - </footer> - </body> -</html> diff --git a/bin/pandoc.rb b/bin/pandoc.rb deleted file mode 100644 index 155ddde..0000000 --- a/bin/pandoc.rb +++ /dev/null @@ -1,95 +0,0 @@ -require 'open3' -require 'json' - -module Pandoc - def self.prog - @prog ||= 'pandoc' - end - def self.prog=(val) - @prog = val - end - def self.load(fmt, input) - cmd = Pandoc::prog + " -t json" - unless fmt.nil? - cmd += " -f " + fmt - end - str = input - if str.respond_to? :read - str = str.read - end - json = '' - errors = '' - Open3::popen3(cmd) do |stdin, stdout, stderr| - stdin.puts(str) - stdin.close - json = stdout.read - errors = stderr.read - end - unless errors.empty? - raise errors - end - return Pandoc::AST::new(json) - end - - class AST - def initialize(json) - @js = JSON::parse(json) - end - - def [](key) - Pandoc::AST::js2sane(@js["meta"][key]) - end - - def js - @js - end - - def to(format) - cmd = Pandoc::prog + " -f json -t " + format.to_s - output = '' - errors = '' - Open3::popen3(cmd) do |stdin, stdout, stderr| - stdin.puts @js.to_json - stdin.close - output = stdout.read - errors = stderr.read - end - unless errors.empty? - raise errors - end - return output - end - - def self.js2sane(js) - if js.nil? - return js - end - case js["t"] - when "MetaMap" - Hash[js["c"].map{|k,v| [k, js2sane(v)]}] - when "MetaList" - js["c"].map{|c| js2sane(c)} - when "MetaBool" - js["c"] - when "MetaString" - js["c"] - when "MetaInlines" - js["c"].map{|c| js2sane(c)}.join() - when "MetaBlocks" - js["c"].map{|c| js2sane(c)}.join("\n") - when "Str" - js["c"] - when "Space" - " " - when "RawInline" - js["c"][1] - when "RawBlock" - js["c"][1] - when "Para" - js["c"].map{|c| js2sane(c)}.join() - else - throw js["t"] - end - end - end -end diff --git a/bin/util.rb b/bin/util.rb deleted file mode 100644 index cd7974b..0000000 --- a/bin/util.rb +++ /dev/null @@ -1,302 +0,0 @@ -# coding: utf-8 -load 'pandoc.rb' -require 'erb' -require 'date' -require 'set' -require 'uri' - -$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/", - "Andrew Murrell" => "https://andrewdm.me/", -} -$person_emails = { - "Luke Shumaker" => "lukeshu@parabola.nu", - "Andrew Murrell" => "ImFromNASA@gmail.com", -} - -$tag_names = { - "DM" => "DMing Resource", - "ES" => "Essay", - "FF" => "Flash Fiction", - "HB" => "Homebrew", - "SS" => "Short Story", - "WP" => "WIP", -} - -$url = URI::parse('https://www.andrewdm.me') - -class Tag - def initialize(abbr) - @abbr = abbr - end - def abbr - @abbr - end - def name - $tag_names[@abbr] - end - def html - return "<a class=\"tag #{abbr}\" href=\"/tags/#{abbr}.html\">#{name}</a>" - end -end - -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 "<a href=\"mailto:#{email}\">#{name}</a>" - elsif not uri.nil? - return "<a href=\"#{uri}\">#{name}</a>" - else - return @name - end - end - def atom - ret = "" - ret += "<name>#{name}</name>" unless name.nil? - ret += "<uri>#{uri}</uri>" unless uri.nil? - ret += "<email>#{email}</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 - "<a href=\"#{url}\">#{name}</a>" - 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? - types = { - 'md' => 'markdown' - } - - ext = File.extname(infile).gsub(/^[.]/, '') - type = types[ext] || ext - @pandoc = Pandoc::load(type, input) - - if @pandoc['pandoc_format'] - @pandoc = Pandoc::load(@pandoc['pandoc_format'], input) - end - end - @pandoc - 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 content ; @content ||= pandoc.to('html5 '+(pandoc['pandoc_flags']||'')) ; end - def head ; @head ||= pandoc['html_head_extra'] ; end - def class ; @class ||= pandoc['class'] ; end - - def tags - if @tags.nil? - raw = pandoc['tags'] || [] - if raw.is_a?(String) - raw = raw.split - end - @tags = raw.map{|tag|Tag.new(tag)} - end - @tags - 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? - 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 published - if @published.nil? - unless _published.nil? - @published = _published - else - unless _updated.nil? - @published = _updated - end - end - # sanity check - unless _published.nil? or _updated.nil? - if _updated < _published - @published = _updated - end - end - end - @published - end - - def updated - if @updated.nil? - unless _updated.nil? - @updated = _updated - else - unless _published.nil? - @updated = _published - end - end - end - @updated - end - - def rights - if published.nil? || updated.nil? - years = '' - else - first = published.year - last = updated.year - - years = `git log --date=format:'%Y' --format='%cd' -- .config/login.sh`.split('\n').map{|s|s.to_i} - years.unshift(first) - years.unshift(last) - - # Remove dups and git years outside of [first,last] - # TODO: simplify year spans - years = Set[*years.select{|i|i > first && i < last}].sort.join(', ') - end - @rights ||= "<p>The content of this page is Copyright © #{years} #{author.html}.</p>\n" + - "<p>This page is licensed under the #{license.html} license.</p>" - end - - def abssrcpath - @srcpath ||= infile.sub(/^(src|out)\//, '/') - end - def absoutpath - @outpath ||= abssrcpath.sub(/\.[^\/.]*$/, '.html').sub(/\/index[.]html$/, '') - end - - def url - @url ||= $url + absoutpath - end - def srcurl - @srcurl ||= $url + abssrcpath - end - - def breadcrumbs - if @breadcrumbs.nil? - bc = [] - u = url.path - u = "/" if u == "" - while u != "/" - bc.unshift("<a href=\"#{u}\">#{File.basename(u, File.extname(u))}</a>") - u = File.dirname(u) - end - bc.unshift("<a href=\"/\">Andrew D. Murrell</a>") - @breadcrumbs = bc.join(' » ') - end - @breadcrumbs - end - - def section - return nil - end -end - -def html_escape(html) - html - .gsub('&', '&') - .gsub('>', '>') - .gsub('<', '<') -end - -class ExternPage - def initialize(metadata) - @metadata = metadata - end - - def title - @metadata['title'] - end - - def content - nil - end - - def tags - if @tags.nil? - raw = @metadata['tags'] || [] - if raw.is_a?(String) - raw = raw.split - end - @tags = raw.map{|tag|Tag.new(tag)} - end - return @tags - end - - def url - return $url + @metadata['url'] - end - - def author - Person.new(@metadata['author'] || "Andrew Murrell") - end - - def published - str = @metadata['published'] - if str.nil? and ! @metadata['updated'].nil? - str = @metadata['updated'] - end - return Date.parse(str) - end - def updated - str = @metadata['updated'] - if str.nil? and ! @metadata['published'].nil? - str = @metadata['published'] - end - return Date.parse(str) - end - - def section - return @metadata['section'] - end -end |