From 1dc021529f88ca4f1ebfed76ffe6378272a23032 Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Sun, 20 May 2018 15:29:28 -0400 Subject: [PATCH] Add links from generated pages to source code on gitweb. --- Rules | 18 ++++++++++++++++++ content/style.css | 15 ++++++++++++++- layouts/default.xml | 7 +++++++ layouts/default.xsl | 18 ++++++++++++++++++ lib/helpers.rb | 10 ++++++++++ 5 files changed, 67 insertions(+), 1 deletion(-) diff --git a/Rules b/Rules index 547a0a9..477d46d 100644 --- a/Rules +++ b/Rules @@ -15,6 +15,24 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +preprocess do + commit = nil + Open3.popen2("git", "rev-parse", "HEAD") do |stdin, stdout, result| + stdin.close + val = stdout.gets + stdout.close + if result.value.success? then commit = val.chomp end + end + + if commit then + @items.each do |item| + if item_source(item) then + item[:gitrev] = commit + end + end + end +end + compile '/**/*.md' do filter :kramdown, header_offset: 1 layout '/default.xml' diff --git a/content/style.css b/content/style.css index 8f6d630..df0a548 100644 --- a/content/style.css +++ b/content/style.css @@ -29,6 +29,19 @@ p { max-width: 50em; } +#footer { + border-top: 1px solid lightgray; + max-width: 50em; + margin: 0; + padding: 0; +} + +#footer>p { + text-align: center; + font-size: 0.9em; + max-width: none; +} + @media (max-width: 512px) { - p { text-align: left; } + p, #footer>p { text-align: left; } } diff --git a/layouts/default.xml b/layouts/default.xml index 47470e0..901b0c3 100644 --- a/layouts/default.xml +++ b/layouts/default.xml @@ -19,6 +19,13 @@ --> <%= @item[:title] %> + + <%= item_source(@item) %> + <%= item.fetch(:gitrev) %> + <%= + Time.now.gmtime.strftime "%Y-%m-%d %H:%M UTC" + %> +

<%= @item.fetch(:header, @item[:title]) %>

<%= yield() %> diff --git a/layouts/default.xsl b/layouts/default.xsl index 5b9aa42..67b7e91 100644 --- a/layouts/default.xsl +++ b/layouts/default.xsl @@ -28,12 +28,26 @@ doctype-system='http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd' /> + + +

+ This document was compiled from + + + + on + + . +

+
+ @@ -50,6 +64,10 @@ + + diff --git a/lib/helpers.rb b/lib/helpers.rb index 18df82e..faa40c3 100644 --- a/lib/helpers.rb +++ b/lib/helpers.rb @@ -24,3 +24,13 @@ def to_xhtml(subpath = "", item = @item) return ret.gsub(/\/+/, "/") end + +def item_source(item = @item) + filename = "content" + item.identifier + + if File.file? filename then + return filename + end + + return nil +end -- 2.43.0