pretty!
authorjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>
Fri, 10 Mar 2006 07:27:11 +0000 (07:27 +0000)
committerjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>
Fri, 10 Mar 2006 07:27:11 +0000 (07:27 +0000)
ikiwiki

diff --git a/ikiwiki b/ikiwiki
index f42be3b01d8e9a74ac15485314c81749cce3063d..72b1021eca97a323bc14724f98c29cab8d285b3e 100755 (executable)
--- a/ikiwiki
+++ b/ikiwiki
@@ -218,12 +218,20 @@ sub linkbacks ($$) {
 
        my @links;
        foreach my $p (keys %links) {
+               next if bestlink($page, $p) eq $page;
                if (grep { length $_ && bestlink($p, $_) eq $page } @{$links{$p}}) {
                        my $href=File::Spec->abs2rel(htmlpage($p), dirname($page));
-                       # TODO: if $p is joey/foo/bar and 
-                       # the $page is joey/foo/baz, make the link text
-                       # just be "bar".
-                       push @links, "<a href=\"$href\">$p</a>";
+                       
+                       # Trim common dir prefixes from both pages.
+                       my $p_trimmed=$p;
+                       my $page_trimmed=$page;
+                       my $dir;
+                       1 while (($dir)=$page_trimmed=~m!^([^/]+/)!) &&
+                               defined $dir &&
+                               $p_trimmed=~s/^\Q$dir\E// &&
+                               $page_trimmed=~s/^\Q$dir\E//;
+                                      
+                       push @links, "<a href=\"$href\">$p_trimmed</a>";
                }
        }