aboutsummaryrefslogtreecommitdiff
path: root/doc/plugins/contrib/unixrelpagespec.mdwn
blob: a35f76c30621e427583938280b87b20ee73973fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
[[!template id=plugin name=unixrelpagespec core=0 author="[[Jogo]]"]]

I don't understand why `./*` correspond to siblings and not subpages.
This is probably only meaningfull with [[plugins/autoindex]] turned on.

Here is a small plugin wich follow usual Unix convention :

- `./*` expand to subpages
- `../*` expand to siblings

---
    #!/usr/bin/perl
    # UnixRelPageSpec plugin.
    # by Joseph Boudou <jogo at matabio dot net>
    
    package IkiWiki::Plugin::unixrelpagespec;
    
    use warnings;
    use strict;
    use IkiWiki 3.00;
    
    sub import {
        inject(
            name => 'IkiWiki::PageSpec::derel',
            call => \&unix_derel
        );
    }
    
    sub unix_derel ($$) {
        my $path = shift;
        my $from = shift;
    
        if ($path =~ m!^\.{1,2}/!) {
            $from =~ s#/?[^/]+$## if (defined $from and $path =~ m/^\.{2}/);
            $path =~ s#^\.{1,2}/##;
            $path = "$from/$path" if length $from;
        }
    
        return $path;
    }
    
    1;