From b864379651d4bfe3d05f98350b720794ffa2806a Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sat, 31 Dec 2016 22:48:59 -0700 Subject: more --- bin/index | 4 +++- bin/index.atom.erb | 4 ++-- bin/index.md.erb | 19 ++++++------------- bin/page.html.erb | 8 +++++--- bin/util.rb | 39 +++++++++++++++++++++++++++++++++++++-- 5 files changed, 53 insertions(+), 21 deletions(-) (limited to 'bin') diff --git a/bin/index b/bin/index index 44cdc35..4f41c5d 100755 --- a/bin/index +++ b/bin/index @@ -2,13 +2,15 @@ # -*- coding: utf-8 -*- load 'util.rb' -template = "index.#{ARGV.shift}.erb" +template = "bin/index.#{ARGV.shift}.erb" +@path = ARGV.shift @pages = [] for filename in ARGV do @pages.push(Page.new(filename)) end + erb = ERB.new(File.read(template)); erb.filename = template erb.run() diff --git a/bin/index.atom.erb b/bin/index.atom.erb index a5e1586..7864e75 100644 --- a/bin/index.atom.erb +++ b/bin/index.atom.erb @@ -1,12 +1,12 @@ - Luke Shumaker's Web Log + AndrewDM.me <%= @path %> <%= @pages.map{|p|p.date}.sort.last.rfc3339 %> - <%= Person.new("Luke Shumaker").atom %> + <%= Person.new("Andrew Murrell").atom %> https://lukeshu.com/blog/ <% @pages.sort_by{|p| p.date}.reverse.each do |page| %> diff --git a/bin/index.md.erb b/bin/index.md.erb index 4da9a5d..392447e 100644 --- a/bin/index.md.erb +++ b/bin/index.md.erb @@ -1,13 +1,6 @@ -Web log entries -=============== - -<% @pages.sort_by{|p| p.date}.reverse.each do |a| %> - * - [<%= a.title %>](./<%= a.slug %>.html)<% end %> +--- +title: "<%= @path %>" +--- + +<% @pages.sort_by{|a|a.published}.each do |a| %> + * - [<%= a.title %>](./<%= a.slug %>.html) (last updated )<% end %> diff --git a/bin/page.html.erb b/bin/page.html.erb index a8e5154..694d11a 100644 --- a/bin/page.html.erb +++ b/bin/page.html.erb @@ -9,9 +9,8 @@
+

<%= @page.breadcrumbs %>

Andrew D. Murrell

-

<%= @page.breadcrumbs %> - (<%= File.extname(@page.src).upcase %>)

-

<%= @page.title %>

+ <% if @page.tags.count > 0 %>

Tags: <%= @page.tags.join(' ') %>

<% end %> + <% if @page.showtitle %>

<%= @page.title %>

<% end %> <%= @page.content %>
diff --git a/bin/util.rb b/bin/util.rb index d95ddba..ec604a3 100644 --- a/bin/util.rb +++ b/bin/util.rb @@ -2,6 +2,7 @@ load 'pandoc.rb' require 'erb' require 'date' +require 'set' $license_urls = { "CC BY-SA-3.0" => 'https://creativecommons.org/licenses/by-sa/3.0/', @@ -86,15 +87,49 @@ class Page 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 date ; @date ||= Date.parse(pandoc['date']) unless pandoc['date'].nil? ; end def slug ; @slug ||= infile.sub(/\..*$/,'').sub(/^.*\//,'') ; end def content ; @content ||= pandoc.to('html5 '+(pandoc['pandoc_flags']||'')) ; end def head ; @head ||= pandoc['html_head_extra'] ; end + def tags ; @tags ||= (pandoc['tags'] || '').split ; 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? + if !updated.nil? && updated < @published + @published = updated + end + 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 rights - @rights ||= "

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

\n" + + years = `git log --date=format:'%Y' --format='%cd' -- .config/login.sh`.split('\n').map{|s|s.to_i} + years.unshift(published.year) unless published.nil? + years.unshift(updated.year) unless updated.nil? + years = Set[*years] + # TODO: simplify year spans + @rights ||= "

The content of this page is Copyright © #{years.sort.join(', ')} #{author.html}.

\n" + "

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

" end -- cgit v1.2.3