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 Index: IkiWiki.pm
4 ===================================================================
5 --- IkiWiki.pm  (revision 9)
6 +++ IkiWiki.pm  (working copy)
7 @@ -391,6 +391,35 @@
8         return "";
9  } #}}}
10
11 +sub bestdir ($$) { #{{{
12 +    my $page=shift;
13 +       my $link=shift;
14 +       my $cwd=$page;
15 +
16 +       if ($link=~s/^\/+//) {
17 +               $cwd="";
18 +       }
19 +
20 +       do {
21 +               my $l=$cwd;
22 +               $l.="/" if length $l;
23 +               $l.=$link;
24 +               if (-d "$config{srcdir}/$l") {
25 +                       return $l;
26 +               }
27 +       } while $cwd=~s!/?[^/]+$!!;
28 +
29 +       if (length $config{userdir}) {
30 +               my $l = "$config{userdir}/".lc($link);
31 +
32 +               if (-d $l) {
33 +                       return $l;
34 +               }
35 +       }
36 +
37 +       return "";
38 +} #}}}
39 +
40  sub isinlinableimage ($) { #{{{
41         my $file=shift;
42
43 ---- 
44 -[[users/arpitjain]]