#!/usr/bin/perl # redirect foo.html -> foo/ for all files marked [[!usedirs_redir ]] # # usedirs_redir.pm # Copyright (C) 2011 by John Heidemann # This file is licensed under terms of the # GNU General Public License, version 2, or (at your option) any later version. # A full copy of that license is at . # package IkiWiki::Plugin::usedirs_redir; use warnings; use strict; use IkiWiki 3.00; use File::Basename; sub import { hook(type => "getsetup", id => "usedirs_redir", call => \&getsetup); hook(type => "preprocess", id => "usedirs_redir", call => \&preprocess); # should we scan => 1 ? } sub getsetup () { return plugin => { safe => 1, rebuild => 1, # format plugin xxx? section => "misc", }, } sub preprocess (@) { my %params = @_; return if (exists $config{usedirs} && !$config{usedirs}); my $page = $params{page} || error "usedirs_redir but unspecified page\n"; my $redirfile = "$page." . $config{htmlext}; my $base = basename($redirfile); my $base_no_suffix = basename($page); will_render($page, $base); writefile($base, $config{destdir} ."/". dirname($redirfile), qq{ }); return; } =pod =head1 to go in ikiwiki/doc/plugins/usedirs_redir.mdwn =begin markdown [[!template id=plugin name=usedirs_redir author="[http://www.isi.edu/~johnh/ John Heidemann] [[!tag type/misc]] This plugin generates redirection files so that the URL turns into . (So both URLs then work.) This redirection is useful to keep compatibility with incoming external links when converting legacy sites, or pre-usedirs sites, if you cannot modify the web server as per [[tips/redirections_for_usedirs]]. To enable the 404 handler you need to: 1. Edit your `.setup` file and add `usedirs_redir` to the `add_plugins` line. 2. Place the \[[!usedirs_redir ]] directive in any documents that require redirection. =end markdown =head1 to go in ikiwiki/doc/ikiwiki/directive/usedirs_redir.mdwn =begin markdown The `usedirs_redir` directive is supplied by the [[!iki plugins/usedirs_redir desc=usedirs_redir]] plugin. This directive marks a page as requiring a redirection, so that the URL turns into . (So both URLs then work.) By default, only pages that include the \[[!usedirs_redir ]] directive get redirections. =end markdown =cut 1;