Add links from generated pages to source code on gitweb.
authorNick Bowler <nbowler@draconx.ca>
Sun, 20 May 2018 19:29:28 +0000 (15:29 -0400)
committerNick Bowler <nbowler@draconx.ca>
Mon, 21 May 2018 17:26:34 +0000 (13:26 -0400)
Rules
content/style.css
layouts/default.xml
layouts/default.xsl
lib/helpers.rb

diff --git a/Rules b/Rules
index 547a0a9dd340c32fd19c6ee58d7671c1febcee28..477d46dabc28c5c605813a4d700b70b14399a1a7 100644 (file)
--- a/Rules
+++ b/Rules
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
 
+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'
index 8f6d630c95405e23428dff8df206b5d4ed3a5e79..df0a54816daacae79b537f5258f9f98d2c570f84 100644 (file)
@@ -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; }
 }
index 47470e0c84c45f12b4ee9c82c352f4c3f434d84e..901b0c36693e48391ddaa272f3efd9067faf6a91 100644 (file)
 -->
 <document>
   <title><%= @item[:title] %></title>
+  <source>
+    <file><%= item_source(@item) %></file>
+    <revision><%= item.fetch(:gitrev) %></revision>
+    <compiletime><%=
+      Time.now.gmtime.strftime "%Y-%m-%d %H:%M UTC"
+    %></compiletime>
+  </source>
   <html xmlns="http://www.w3.org/1999/xhtml">
     <h1><%= @item.fetch(:header, @item[:title]) %></h1>
     <%= yield() %>
index 5b9aa42a71118a08556c4da870b033d9b068148c..67b7e9199484f6daf67304c4e8eb28149bcc17a3 100644 (file)
   doctype-system='http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd' />
 <xsl:strip-space elements='*' />
 
+<xsl:param name='source-uri'
+  select='"//git.draconx.ca/gitweb/homepage.git/blob/"' />
 <xsl:param name='site-title' select='"The Citrine Citadel"' />
 
 <xsl:template match='node()|@*'>
   <xsl:copy><xsl:apply-templates select='node()|@*' /></xsl:copy>
 </xsl:template>
 
+<xsl:template match='source'>
+  <p>
+    <xsl:text>This document was compiled from </xsl:text>
+    <a href='{concat($source-uri, revision, ":", file)}'>
+      <xsl:value-of select='file' />
+    </a>
+    <xsl:text> on </xsl:text>
+    <xsl:value-of select='compiletime' />
+    <xsl:text>.</xsl:text>
+  </p>
+</xsl:template>
+
 <xsl:template match='/'>
   <html>
     <head>
     <body>
       <xsl:apply-templates select='/document/xhtml:html/@*' />
       <xsl:apply-templates select='/document/xhtml:html/node()' />
+
+      <div id='footer'>
+        <xsl:apply-templates select='/document/source' />
+      </div>
     </body>
   </html>
 </xsl:template>
index 18df82e5a9b7a2430d0e5e43814f958c0d637e52..faa40c3533222aa3879cd3e3ee8f2563cf5328f1 100644 (file)
@@ -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