<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>siterel2pagerel (third party plugin)</title> <meta name="viewport" content="width=device-width, initial-scale=1" /> <link rel="stylesheet" href="../../style.css" type="text/css" /> <link rel="stylesheet" href="../../local.css" type="text/css" /> </head> <body> <div class="page"> <div class="pageheader"> <div class="header"> <span> <span class="parentlinks"> <a href="../../index.html">ikiwiki</a>/ <a href="../../plugins.html">plugins</a>/ <a href="../contrib.html">contrib</a>/ </span> <span class="title"> siterel2pagerel (third party plugin) </span> </span> </div> </div> <div id="pagebody"> <div id="content" role="main"> <p><span class="infobox"> Plugin: siterel2pagerel<br /> Author: <span class="createlink">PaulWise</span><br /> Included in ikiwiki: no<br /> Enabled by default: no<br /> Included in <a href="../goodstuff.html">goodstuff</a>: no<br /> Currently enabled: no<br /> </span></p> <p>This is a simple plugin to convert all site-relative links to page-relative links (converts /foo into ../../../foo or similar). It works as a postprocessing filter, allowing it to work on mdwn, wiki, html, rst and any other format that produces html. The code is available here:</p> <pre><code>#!/usr/bin/perl # quick HTML siterel2pagerel link hack by Paul Wise package IkiWiki::Plugin::siterel2pagerel; use warnings; use strict; use IkiWiki 2.00; sub import { hook(type => "sanitize", id => "siterel2pagerel", call => \&siterel2pagerel); } sub siterel2pagerel (@) { my %params=@_; my $baseurl=IkiWiki::baseurl($params{page}); my $content=$params{content}; $content=~s/(<a(?:\s+(?:class|id)\s*="?\w+"?)?)\s+href=\s*"\/([^"]*)"/$1 href="$baseurl$2"/mig; $content=~s/(<img(?:\s+(?:class|id|width|height)\s*="?\w+"?)*)\s+src=\s*"\/([^"]*)"/$1 src="$baseurl$2"/mig; # FIXME: do <script and everything else that can have URLs in it return $content; } 1 </code></pre> </div> </div> <div id="footer" class="pagefooter" role="contentinfo"> <div id="pageinfo"> <div class="pagedate"> Last edited <span class="date">Tue Feb 26 23:01:54 2019</span> <!-- Created <span class="date">Tue Feb 26 23:01:54 2019</span> --> </div> </div> <!-- from ikiwiki --> </div> </div> </body> </html>