]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki/Plugin/link.pm
standardising and documenting getsetup
[ikiwiki.git] / IkiWiki / Plugin / link.pm
index 51afaec9e7392b3ca15fe6b8c39db5d4b90d88bf..2ea6aa19eebbfdb17b0a1859eb79ca511ced8504 100644 (file)
@@ -11,6 +11,7 @@ sub import { #{{{
        hook(type => "checkconfig", id => "link", call => \&checkconfig);
        hook(type => "linkify", id => "link", call => \&linkify);
        hook(type => "scan", id => "link", call => \&scan);
+       hook(type => "renamepage", id => "link", call => \&renamepage);
 } # }}}
 
 sub checkconfig () { #{{{
@@ -87,13 +88,19 @@ sub renamepage (@) { #{{{
        my $new=$params{newpage};
 
        $params{content} =~ s{(?<!\\)$link_regexp}{
-               my $link=$2;
-               if (bestlink($page, $2) eq $old) {
-                       if (index($2, "/") == 0) {
-                               $link="/$new";
+               my $linktext=$2;
+               my $link=$linktext;
+               if (bestlink($page, IkiWiki::linkpage($linktext)) eq $old) {
+                       $link=IkiWiki::pagetitle($new, 1);
+                       $link=~s/ /_/g;
+                       if ($linktext =~ m/.*\/*?[A-Z]/) {
+                               # preserve leading cap of last component
+                               my @bits=split("/", $link);
+                               $link=join("/", @bits[0..$#bits-1], ucfirst($bits[$#bits]));
                        }
-                       else {
-                               $link=$new;
+                       if (index($linktext, "/") == 0) {
+                               # absolute link
+                               $link="/$link";
                        }
                }
                defined $1