summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2016-12-31 22:48:59 -0700
committerLuke Shumaker <lukeshu@sbcglobal.net>2016-12-31 22:48:59 -0700
commitb864379651d4bfe3d05f98350b720794ffa2806a (patch)
treec4bc81a8371694d661b10118b4932480aaa37d0b /bin
parent7445ea9d56071cfca247689e22c6fded65c3f968 (diff)
more
Diffstat (limited to 'bin')
-rwxr-xr-xbin/index4
-rw-r--r--bin/index.atom.erb4
-rw-r--r--bin/index.md.erb19
-rw-r--r--bin/page.html.erb8
-rw-r--r--bin/util.rb39
5 files changed, 53 insertions, 21 deletions
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 @@
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
- <title>Luke Shumaker's Web Log</title>
+ <title>AndrewDM.me <%= @path %></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.date}.sort.last.rfc3339 %></updated>
- <author><%= Person.new("Luke Shumaker").atom %></author>
+ <author><%= Person.new("Andrew Murrell").atom %></author>
<id>https://lukeshu.com/blog/</id>
<% @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
-===============
-<style>
-li {
- list-style-type: none;
-}
-time {
- color: #AAAAAA;
- font-family: monospace;
-}
-</style>
-<% @pages.sort_by{|p| p.date}.reverse.each do |a| %>
- * <time><%= a.date.strftime('%Y-%m-%d') %></time> - [<%= a.title %>](./<%= a.slug %>.html)<% end %>
+---
+title: "<%= @path %>"
+---
+
+<% @pages.sort_by{|a|a.published}.each do |a| %>
+ * <time><%= a.published.strftime('%Y-%m-%d') %></time> - [<%= a.title %>](./<%= a.slug %>.html) (last updated <time><%= a.updated.strftime('%Y-%m-%d') %></time>)<% 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 @@
</head>
<body>
<header>
+ <p><%= @page.breadcrumbs %></p>
<h1>Andrew D. Murrell</h1>
- <p><%= @page.breadcrumbs %>
- (<a href="<%= File.basename(@page.src) %>"><%= File.extname(@page.src).upcase %></a>)</p>
<nav>
<ul>
<li><a href="/">Projects</a>
@@ -25,11 +24,14 @@
</nav>
</header>
<article>
- <h1 class=title><%= @page.title %></h1>
+ <% if @page.tags.count > 0 %><p>Tags: <%= @page.tags.join(' ') %></p><% end %>
+ <% if @page.showtitle %><h1 class=title><%= @page.title %></h1><% end %>
<%= @page.content %>
</article>
<footer>
<%= @page.rights %>
+ <p>Page source: <a href="<%= File.basename(@page.src) %>"><%= File.basename(@page.src) %></a></p>
+ <p>Website source: <a href="https://git.andrewdm.me/www.git">www.git</a></p>
</footer>
</body>
</html>
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 ||= "<p>The content of this page is Copyright © #{date.year unless date.nil?} #{author.html}.</p>\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 ||= "<p>The content of this page is Copyright © #{years.sort.join(', ')} #{author.html}.</p>\n" +
"<p>This page is licensed under the #{license.html} license.</p>"
end