]> sipb.mit.edu Git - ikiwiki.git/commitdiff
* map: Render pages on the way to subpages whose parent pages
authorjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>
Sat, 22 Sep 2007 16:32:24 +0000 (16:32 +0000)
committerjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>
Sat, 22 Sep 2007 16:32:24 +0000 (16:32 +0000)
  are not included in the map. Include special styling for such pages.
* map: Remove common prefixes and don't over-indent.
* Add class option to htmllink().

IkiWiki.pm
IkiWiki/Plugin/map.pm
debian/changelog
doc/plugins/write.mdwn
doc/style.css

index 720afdecd0faabf496f8e93797be1174b010c91c..1c15e9299bd0774255b89eaf080b79e54af1a481 100644 (file)
@@ -588,6 +588,9 @@ sub htmllink ($$$;@) { #{{{
        if (defined $opts{rel}) {
                push @attrs, ' rel="'.$opts{rel}.'"';
        }
+       if (defined $opts{class}) {
+               push @attrs, ' class="'.$opts{class}.'"';
+       }
 
        return "<a href=\"$bestlink\"@attrs>$linktext</a>";
 } #}}}
index 2ff840ff7b0121b55f7ece7654c579f9fdc7403a..97450eb6dd988fbe2d04cf684528658406ca4ddb 100644 (file)
@@ -19,43 +19,80 @@ sub preprocess (@) { #{{{
        my %params=@_;
        $params{pages}="*" unless defined $params{pages};
        
+       my $common_prefix;
+
        # Get all the items to map.
-       my @mapitems = ();
+       my %mapitems;
        foreach my $page (keys %pagesources) {
                if (pagespec_match($page, $params{pages}, location => $params{page})) {
-                       push @mapitems, "/".$page;
+                       $mapitems{$page}=1;
+
+                       # Check for a common prefix.
+                       if (! defined $common_prefix) {
+                               $common_prefix=$page;
+                       }
+                       elsif (length $common_prefix &&
+                              $page !~ /^\Q$common_prefix\E(\/|$)/) {
+                               my @a=split(/\//, $page);
+                               my @b=split(/\//, $common_prefix);
+                               $common_prefix="";
+                               while (@a && @b && $a[0] eq $b[0]) {
+                                       $common_prefix.=shift(@a);
+                                       shift @b;
+                               }
+                       }
                }
        }
+       
+       # Common prefix should not be a page in the map.
+       while (length $common_prefix && exists $mapitems{$common_prefix}) {
+               $common_prefix=IkiWiki::dirname($common_prefix);
+       }
 
        # Needs to update whenever a page is added or removed, so
        # register a dependency.
        add_depends($params{page}, $params{pages});
        # Explicitly add all currently shown pages, to detect when pages
        # are removed.
-       add_depends($params{page}, join(" or ", @mapitems));
+       add_depends($params{page}, join(" or ", keys %mapitems));
 
        # Create the map.
        my $parent="";
        my $indent=0;
        my $openli=0;
-       my $map = "<div class='map'>\n";
-       foreach my $item (sort @mapitems) {
-               my $depth = ($item =~ tr/\//\//);
+       my $map = "<div class='map'>\n<ul>\n";
+       foreach my $item (sort keys %mapitems) {
+               $item=~s/^\Q$common_prefix\E\/// if length $common_prefix;
+               my $depth = ($item =~ tr/\//\//) + 1;
                my $baseitem=IkiWiki::dirname($item);
-               while (length $parent && length $baseitem && $baseitem !~ /^\Q$parent\E/) {
+               while (length $parent && length $baseitem && $baseitem !~ /^\Q$parent\E(\/|$)/) {
                        $parent=IkiWiki::dirname($parent);
                        $indent--;
-                       $map.="</li></ul>\n";
+                       $map .= "</li>\n";
+                       if ($indent > 0) {
+                               $map .= "</ul>\n";
+                       }
                }
                while ($depth < $indent) {
                        $indent--;
-                       $map.="</li></ul>\n";
+                       $map .= "</li>\n";
+                       if ($indent > 0) {
+                               $map .= "</ul>\n";
+                       }
                }
+               my @bits=split("/", $item);
+               my $p="";
+               $p.="/".shift(@bits) for 1..$indent;
                while ($depth > $indent) {
                        $indent++;
-                       $map.="<ul>\n";
+                       if ($indent > 1) {
+                               $map .= "<ul>\n";
+                       }
                        if ($depth > $indent) {
-                               $map .= "<li>\n";
+                               $p.="/".shift(@bits);
+                               $map .= "<li>"
+                                       .htmllink($params{page}, $params{destpage}, $p, class => "mapparent")
+                                       ."</span>\n";
                                $openli=1;
                        }
                        else {
@@ -64,14 +101,15 @@ sub preprocess (@) { #{{{
                }
                $map .= "</li>\n" if $openli;
                $map .= "<li>"
-                       .htmllink($params{page}, $params{destpage}, $item)
-                       ."\n";
+                       .htmllink($params{page}, $params{destpage}, 
+                               "/".$common_prefix."/".$item, class => "mapitem")
+                       ."</span>\n";
                $openli=1;
                $parent=$item;
        }
        while ($indent > 0) {
                $indent--;
-               $map.="</li></ul>\n";
+               $map .= "</li>\n</ul>\n";
        }
        $map .= "</div>\n";
        return $map;
index 3041fad45cd1152b0729cd721fad2e5db4379652..377bb41b8a51f2bcdd743c8387b4407cf3990bff 100644 (file)
@@ -5,11 +5,12 @@ ikiwiki (2.9) UNRELEASED; urgency=low
     Closes: #443344
   * map: Fully specify paths to links to avoid issues when the bestlink
     didn't point to the correct page.
-  * map: Render empty nodes on the way to subpages whose parent pages
-    are not included in the map.
-  * map: Fix valid html issue.
+  * map: Render pages on the way to subpages whose parent pages
+    are not included in the map. Include special styling for such pages.
+  * map: Remove common prefixes and don't over-indent.
+  * Add class option to htmllink().
 
- -- Joey Hess <joeyh@debian.org>  Fri, 21 Sep 2007 13:28:32 -0400
+ -- Joey Hess <joeyh@debian.org>  Sat, 22 Sep 2007 12:31:22 -0400
 
 ikiwiki (2.8) unstable; urgency=low
 
index 4ec9e8c7bf7cc313d2d83a4384354c54c5708c5a..77f336dca01ad966a09f8e9c461ab0df82100b48 100644 (file)
@@ -412,7 +412,8 @@ control some options. These are:
 * forcesubpage  - set to force a link to a subpage
 * linktext - set to force the link text to something
 * anchor - set to make the link include an anchor
-* rel - set to add a rel attribute to the link.
+* rel - set to add a rel attribute to the link
+* class - set to add a css class to the link
 
 #### `readfile($;$)`
 
index 0399031f81feebd509a468c3d299681b557daca3..0fa15d2b1a10a26254ecab2141a8954e31675bc4 100644 (file)
@@ -49,6 +49,10 @@ div.tags {
        margin-top: 1em;
 }
 
+.mapparent {
+       text-decoration: none;
+}
+
 #backlinks {
        margin-top: 1em;
 }