]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki/Plugin/inline.pm
Bug#473987: [PATCH] Links relative to baseurl mangled in atom/rss feeds
[ikiwiki.git] / IkiWiki / Plugin / inline.pm
index c734bd9a69ecada131dbf3d4ea411bc1cfe58b5f..8f7cd826e4ea801cc49a7a57bc7e3e09084b0782 100644 (file)
@@ -388,9 +388,18 @@ sub absolute_urls ($$) { #{{{
 
        my $url=$baseurl;
        $url=~s/[^\/]+$//;
-       
+
+        # what is the non path part of the url? (need it for relative url's starting with /
+        my $top_uri = URI->new($url);
+        $top_uri->path_query("/"); # reset the path
+        my $urltop = $top_uri->as_string;
+        $urltop=~s/\/*$//;
+
        $content=~s/(<a(?:\s+(?:class|id)\s*="?\w+"?)?)\s+href=\s*"(#[^"]+)"/$1 href="$baseurl$2"/mig;
-       $content=~s/(<a(?:\s+(?:class|id)\s*="?\w+"?)?)\s+href=\s*"(?!\w+:)([^"]+)"/$1 href="$url$2"/mig;
+        # Relative URL
+       $content=~s/(<a(?:\s+(?:class|id)\s*="?\w+"?)?)\s+href=\s*"(?!\w+:)([^\/][^"]*)"/$1 href="$url$2"/mig;
+        # relative to the top of the site
+       $content=~s/(<a(?:\s+(?:class|id)\s*="?\w+"?)?)\s+href=\s*"(?!\w+:)(\/[^"]*)"/$1 href="$urltop$2"/mig;
        $content=~s/(<img(?:\s+(?:class|id|width|height)\s*="?\w+"?)*)\s+src=\s*"(?!\w+:)([^"]+)"/$1 src="$url$2"/mig;
        return $content;
 } #}}}