You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by ni...@apache.org on 2011/03/02 14:23:46 UTC

svn commit: r1076213 - in /chemistry/site/trunk: content/sitemap.html content/sitemap.mdtext lib/view.pm

Author: nick
Date: Wed Mar  2 13:23:45 2011
New Revision: 1076213

URL: http://svn.apache.org/viewvc?rev=1076213&view=rev
Log:
Add sitemap support

Added:
    chemistry/site/trunk/content/sitemap.html
      - copied, changed from r1076168, chemistry/site/trunk/content/sitemap.mdtext
Removed:
    chemistry/site/trunk/content/sitemap.mdtext
Modified:
    chemistry/site/trunk/lib/view.pm

Copied: chemistry/site/trunk/content/sitemap.html (from r1076168, chemistry/site/trunk/content/sitemap.mdtext)
URL: http://svn.apache.org/viewvc/chemistry/site/trunk/content/sitemap.html?p2=chemistry/site/trunk/content/sitemap.html&p1=chemistry/site/trunk/content/sitemap.mdtext&r1=1076168&r2=1076213&rev=1076213&view=diff
==============================================================================
--- chemistry/site/trunk/content/sitemap.mdtext (original)
+++ chemistry/site/trunk/content/sitemap.html Wed Mar  2 13:23:45 2011
@@ -1,2 +1,3 @@
-Title: SiteMap
-{children:all=true|page=Index} 
+{% extends "standard.html" %}
+{% block title %}SiteMap{% endblock %}
+{% block content %}{{ sitemap|safe }}{% endblock %}

Modified: chemistry/site/trunk/lib/view.pm
URL: http://svn.apache.org/viewvc/chemistry/site/trunk/lib/view.pm?rev=1076213&r1=1076212&r2=1076213&view=diff
==============================================================================
--- chemistry/site/trunk/lib/view.pm (original)
+++ chemistry/site/trunk/lib/view.pm Wed Mar  2 13:23:45 2011
@@ -34,6 +34,10 @@ sub normal_page {
     read_text_file $file, \%args;
     $args{breadcrumbs} = breadcrumbs($args{path}, $args{headers});
 
+    if($args{path} eq "sitemap.html" || $args{path} eq "/sitemap.html") {
+      sitemap($file, \%args);
+    }    
+
     my $page_path = $file;
     $page_path =~ s/\.[^.]+$/.page/;
     if (-d $page_path) {
@@ -87,6 +91,96 @@ sub breadcrumbs {
     return join " &raquo ", @rv;
 }
 
+# Generate a CWiki style sitemap
+sub sitemap {
+   my ($file, $argsref) = @_;
+
+   # Find the list of files
+   my ($dir) = ($file =~ /^(.*)\/.*?/);
+   my $entries = {};
+   sitemapFind($dir, $entries);
+
+   my $sitemap = "<ul>\n";
+   $sitemap = sitemapRender($sitemap, $entries, "");
+   $sitemap .= "</ul>\n";
+   $argsref->{'sitemap'} = $sitemap;
+}
+sub sitemapFind {
+   my ($dir, $entries) = @_;
+   $entries->{"title"} = "";
+   $entries->{"entries"} = {};
+   my %entries = ( "title"=>"", "entries"=>{} );
+
+   foreach my $item (<$dir/*>) {
+      my ($rel) = ($item =~ /^.*\/(.*?)$/);
+
+      if(-d $item) {
+         $entries->{"entries"}->{$rel} = {};
+         sitemapFind($item, $entries->{"entries"}->{$rel});
+      } else {
+         # Grab the title
+         my $title = $rel;
+         if($rel =~ /\.mdtext$/) {
+             my %args;
+             read_text_file $item, \%args;
+             $title = $args{"headers"}->{"title"};
+         } elsif ($rel =~ /\.png$/ || $rel =~ /\.jpg$/) {
+            next;
+         } else {
+             open F, "<$item";
+             my $file = "";
+             while(my $line = <F>) {
+                $file .= $line;
+             }
+             close F;
+
+             if($file =~ /block\s+title\s*\%\}(.*?)\{/) {
+                $title = $1;
+             } elsif($file =~ /title\>(.*?)\</) {
+                $title = $1;
+             }
+         }
+
+         # Process
+         if($rel =~ /^index\.(html|mdtext)$/) {
+            $entries->{"title"} = $title;
+         } else {
+            $entries->{entries}->{$rel}->{title} = $title;
+         }
+      }
+   }
+   return %entries;
+}
+sub sitemapRender {
+   my ($sitemap, $dir, $path) = @_;
+   my %entries = %{$dir->{"entries"}};
+
+   foreach my $e (sort keys %entries) {
+      my $fn = $e;
+      $fn =~ s/\.mdtext/.html/;
+      if($entries{$e}->{entries}) {
+         $fn .= "/";
+      }
+      if($fn eq "images/" or $fn eq "resources/") {
+         next;
+      }
+
+      my $title = $entries{$e}->{title};
+      unless($title) {
+         $title = $e;
+      }
+
+      $sitemap .= "<li><a href=\"$path/$fn\">".$title."</a>";
+      if($entries{$e}->{entries}) {
+         $sitemap .= "<ul>\n";
+         $sitemap = sitemapRender($sitemap, $entries{$e}, "$path/$e");
+         $sitemap .= "</ul>\n";
+      }
+      $sitemap .= "</li>\n";
+   }
+   return $sitemap;
+}
+
 1;
 
 =head1 LICENSE