web commit by arpitjain11
[ikiwiki] / doc / todo / Bestdir_along_with_bestlink_in_IkiWiki.pm.mdwn
1 This patch adds function bestdir() which returns best directory from the directory structure. This is in addition to the bestlink() function which is there in IkiWiki.pm 
2
3 -------
4
5 Index: IkiWiki.pm
6 ===================================================================
7 --- IkiWiki.pm  (revision 9)
8 +++ IkiWiki.pm  (working copy)
9 @@ -391,6 +391,35 @@
10         return "";
11  } #}}}
12
13 +sub bestdir ($$) { #{{{
14 +    my $page=shift;
15 +       my $link=shift;
16 +       my $cwd=$page;
17 +
18 +       if ($link=~s/^\/+//) {
19 +               $cwd="";
20 +       }
21 +
22 +       do {
23 +               my $l=$cwd;
24 +               $l.="/" if length $l;
25 +               $l.=$link;
26 +               if (-d "$config{srcdir}/$l") {
27 +                       return $l;
28 +               }
29 +       } while $cwd=~s!/?[^/]+$!!;
30 +
31 +       if (length $config{userdir}) {
32 +               my $l = "$config{userdir}/".lc($link);
33 +
34 +               if (-d $l) {
35 +                       return $l;
36 +               }
37 +       }
38 +
39 +       return "";
40 +} #}}}
41 +
42  sub isinlinableimage ($) { #{{{
43         my $file=shift;
44
45 ---- 
46 -[[users/arpitjain]]