]> sipb.mit.edu Git - ikiwiki.git/blob - doc/plugins/contrib/unixrelpagespec.mdwn
formatting
[ikiwiki.git] / doc / plugins / contrib / unixrelpagespec.mdwn
1 [[!template id=plugin name=unixrelpagespec core=0 author="[[Jogo]]"]]
2
3 I don't understand why `./*` correspond to siblings and not subpages.
4 This is probably only meaningfull with [[plugins/autoindex]] turned on.
5
6 Here is a small plugin wich follow usual Unix convention :
7
8 - `./*` expand to subpages
9 - `../*` expand to siblings
10
11 ---
12     #!/usr/bin/perl
13     # UnixRelPageSpec plugin.
14     # by Joseph Boudou <jogo at matabio dot net>
15     
16     package IkiWiki::Plugin::unixrelpagespec;
17     
18     use warnings;
19     use strict;
20     use IkiWiki 3.00;
21     
22     sub import {
23         inject(
24             name => 'IkiWiki::PageSpec::derel',
25             call => \&unix_derel
26         );
27     }
28     
29     sub unix_derel ($$) {
30         my $path = shift;
31         my $from = shift;
32     
33         if ($path =~ m!^\.{1,2}/!) {
34             $from =~ s#/?[^/]+$## if (defined $from and $path =~ m/^\.{2}/);
35             $path =~ s#^\.{1,2}/##;
36             $path = "$from/$path" if length $from;
37         }
38     
39         return $path;
40     }
41     
42     1;