]> git.draconx.ca Git - homepage.git/blobdiff - layouts/default.xsl
Implement dark mode without using CSS variables.
[homepage.git] / layouts / default.xsl
index 2e14ce8e29fa93cb737624d069474c95548040db..d5be1039e5061cf8c8dc2eff408eeb306c35de0a 100644 (file)
@@ -2,7 +2,7 @@
 <!--
   Nick's web site: XHTML output stage
 
-  Copyright © 2018-2021 Nick Bowler
+  Copyright © 2018-2022 Nick Bowler
 
   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   <xsl:variable name='node' select='.' />
   <p>
     <xsl:choose>
-      <xsl:when test='/document/image[license != $node]'>
+      <xsl:when test='/document/image[license/identifier != $node/identifier]'>
         <xsl:text>Except as otherwise noted, copying</xsl:text>
       </xsl:when>
       <xsl:otherwise>Copying</xsl:otherwise>
   </xsl:if>
 </xsl:template>
 
-<xsl:template match='xhtml:p[count(*)=1 and normalize-space(text())=""
-                             and descendant::xhtml:img]'>
+<xsl:template name='imgpara' match='xhtml:p[count(*)=1]
+                                           [normalize-space(text())=""]
+                                           [descendant::xhtml:img]'>
   <xsl:copy>
     <xsl:apply-templates select='@*[local-name() != "class"]' />
     <xsl:attribute name='class'>
   </xsl:copy>
 </xsl:template>
 
+<xsl:key name='gallery'
+  match='xhtml:html/xhtml:p[descendant::*[@generate-gallery]]'
+  use='generate-id(
+        ( ( preceding-sibling::*[not(descendant::*[@generate-gallery])][1]
+          /following-sibling::* ) | self::* ) [1])' />
+
+<xsl:template match='@generate-gallery' />
+<xsl:template match='xhtml:html/xhtml:p[descendant::*[@generate-gallery]]' />
+<xsl:template match='xhtml:html/xhtml:p[key("gallery", generate-id(.))]'>
+  <xsl:variable name='images' select='key("gallery", generate-id(.))' />
+  <xsl:choose>
+    <xsl:when test='count($images) > 1'>
+      <div class='gallery'>
+        <xsl:for-each select='$images'>
+          <xsl:call-template name='imgpara' />
+        </xsl:for-each>
+      </div>
+    </xsl:when>
+    <xsl:otherwise>
+      <xsl:call-template name='imgpara' />
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
 <xsl:template match='/'>
   <html>
     <head>
       <meta name='viewport' content='width=device-width, initial-scale=1' />
       <link rel='stylesheet' type='text/css' href='/style.css' />
+      <link rel='alternate stylesheet' type='text/css' href='/dark.css'
+        title='Dark Style' />
       <link rel="icon" href="data:," />
       <title>
         <xsl:variable name='page-title' select='string(/document/title)' />
       <div id='footer'>
         <xsl:apply-templates select='/document/copyright' />
         <xsl:apply-templates select='/document/license' />
-        <xsl:if test='/document/image'>
+        <xsl:if test='/document/image[copyright != /document/copyright
+                      or license/identifier != /document/license/identifier]'>
           <xsl:call-template name='image-attribution' />
         </xsl:if>
         <xsl:apply-templates select='/document/source' />