Let people select older versions of the documentation
authorMike Cardwell <github@grepular.com>
Wed, 7 Sep 2011 14:03:23 +0000 (15:03 +0100)
committerMike Cardwell <github@grepular.com>
Wed, 7 Sep 2011 14:03:23 +0000 (15:03 +0100)
script/gen.pl
templates/web/docs.css [new file with mode: 0644]
templates/web/docs.js [new file with mode: 0644]
templates/web/docs.xsl

index 3cf3acd52e32929f48cea8d0ace4f80856fa349f..f3e04861410a73976aad42d4ad24f7561b01cc70 100755 (executable)
@@ -21,6 +21,7 @@ my $canonical_url = 'http://www.exim.org/';
 my %opt = parse_arguments();
 
 ## Generate the pages
+my %cache; # General cache object
 do_doc( 'spec',   $_ ) foreach @{ $opt{spec}   || [] };
 do_doc( 'filter', $_ ) foreach @{ $opt{filter} || [] };
 do_web() if exists $opt{web};
@@ -332,6 +333,9 @@ sub transform {
     ## Add the current version of Exim to the XML
     $xml->documentElement()->appendTextChild( 'current_version', $opt{latest} );
 
+    ## Add the old versions of Exim to the XML
+    $xml->documentElement()->appendTextChild( 'old_versions', $_ ) foreach old_docs_versions();
+
     ## Parse the ".xsl" file as XML
     my $xsl = XML::LibXML->new()->parse_file($xsl_path) or die $!;
 
@@ -350,6 +354,18 @@ sub transform {
     close $out;
 }
 
+## Look in the docroot for old versions of the documentation 
+sub old_docs_versions {
+   if( !exists $cache{old_docs_versions} ){
+      my @versions;
+      foreach( glob("$opt{docroot}/exim-html-*") ){
+         push @versions, $1 if /-(\d+(?:\.\d+)?)$/ && $1 < $opt{latest} && -d $_;
+      }
+      $cache{old_docs_versions} = [reverse sort {$a<=>$b} @versions];
+   }
+   return @{$cache{old_docs_versions}};
+}
+
 ## error_help
 sub error_help {
     my $msg = shift;
diff --git a/templates/web/docs.css b/templates/web/docs.css
new file mode 100644 (file)
index 0000000..9056a73
--- /dev/null
@@ -0,0 +1,3 @@
+body.no-js p.manual_info select {
+       display:        none;
+}
diff --git a/templates/web/docs.js b/templates/web/docs.js
new file mode 100644 (file)
index 0000000..8e604bc
--- /dev/null
@@ -0,0 +1,10 @@
+(function($){
+       $('p.manual_info select').each(function(){
+               $(this).change(function(e){
+                       if( $(this).val().match(/^[0-9\.]+$/) ){
+                               var href = $(this).parent().find('a').attr('href').replace('-current/','-'+$(this).val()+'/');
+                               document.location.href=href;
+                       }
+               });
+       });
+})(jQuery);
index 2517496cb7f4c94949ae3110eec85b028e58f808..1b154c67ae638bca0391d6e82975f0d77c4f30c4 100644 (file)
        <!-- Title -->
                <xsl:variable name="html.head.title" select="'Documentation for Exim'"/>
 
-        <!-- Canonical -->
-                <xsl:variable name="html.head.append">
-                        <link rel="canonical" href="http://www.exim.org/docs.html"/>
-                </xsl:variable>
+                
+       <xsl:variable name="html.head.append">
+
+               <!-- Canonical -->
+                       <link rel="canonical" href="http://www.exim.org/docs.html"/>
+
+               <!-- CSS -->
+                       <link rel="stylesheet" type="text/css" href="docs.css"/>
+       </xsl:variable>
+
+       <!-- JavaScript -->
+               <xsl:variable name="html.body.append">
+                       <script type="text/javascript" src="docs.js"/>
+               </xsl:variable>
 
        <!-- CONTENT -->
                <xsl:template name="content">
 
                                        <xsl:text> - The master documentation for Exim containing all required detail to install, configure and use Exim. </xsl:text>
                                        <span class="changed">Changes to the documentation (normally reflecting changes to the functionality of Exim) are shown on a green background like this segment.</span>
+                                       <br/><select name="spec_old_version">
+                                               <option value="">View Older Versions</option>
+                                               <xsl:for-each select="/content/old_versions">
+                                                       <option value="{text()}"><xsl:value-of select="text()"/></option>
+                                               </xsl:for-each>
+                                       </select>
                                </p>
 
                                <p class="manual_info">
                                        <xsl:text> </xsl:text>
                                        <a href="{$docroot}/exim-pdf-current/doc/filter.pdf">(PDF)</a>
                                        <xsl:text> - Additional information on the Exim filter language.</xsl:text>
+                                       <br/><select name="filter_old_version">
+                                               <option value="">View Older Versions</option>
+                                               <xsl:for-each select="/content/old_versions">
+                                                       <option value="{text()}"><xsl:value-of select="text()"/></option>
+                                               </xsl:for-each>
+                                       </select>
                                </p>
 
                        <!-- HOWTOs -->