* Ping
[ikiwiki] / doc / todo / inline:_numerical_ordering_by_title.mdwn
1 Could you please add numerical ordering by title to [[inline|plugins/inline]]
2 plugin? Now I can do only alphabetical order by title, but sometime it's not enough.
3
4 BTW, it seems that ordering by title is rather ordering by filename of page.
5 For me "title" means title of page I can set using `title` parameter
6 of [[meta|plugins/meta]] plugin :)
7
8 Why do I need that feature? I've just been migrating an info site of our university
9 [mail system](http://poczta.uw.edu.pl/) to Ikiwiki from very static, console handling
10 Makefile+[WML](http://thewml.org/)+XML+XSL=HTML solution. I have many news files
11 (`1.mdwn`, `2.mdwn`, etc.) and unfortunately I did very stupid thing. I've commited
12 all of them in the same revision of our Subversion repo...
13
14 Now I have a problem with sorting these files using inline plugin. I can't do
15 sorting by age, because both old and young news files have the same age. I can't
16 sort by title too. For example, when I sort them by title, then `9.mdwn` page is
17 between `90.mdwn` and `89.mdwn` pages... It sucks, of course. Sorting by mtime
18 also is not a solution for me, because it means that I can't touch/fix old news
19 anymore.
20
21 Do you have any idea how to workaround that issue? --[[Paweł|ptecza]]
22
23 > Maybe you can rename `9.mdwn` to `09.mdwn`? See `rename(1)`, it renames multiple files
24 > in one go. --[[buo]]
25
26 >> Thanks for your suggestion! But what about if number of my news files grows to 100+?
27
28 >>     $ ls
29 >>     09.mdwn  100.mdwn  101.mdwn  102.mdwn  89.mdwn  90.mdwn
30
31 >> I don't want to rename all previous files to add `0` prefix. --[[Paweł|ptecza]]
32
33 ---
34
35 Below is my simple patch. Feel free to use it or comment!
36
37 I have also 2 considerations for inline sorting:
38
39 1. Maybe changing name of `sort` parameter to `sortby` or `sortkey` will
40    be good idea?
41 1. Maybe you should use `title` sort key for title from meta plugin and `name`, 
42    `filename`, `page` or `pagename` for page names? In the future you can also
43    sort by meta author, license or another key.
44
45 --[[Paweł|ptecza]]
46
47     --- inline.pm-orig  2008-09-02 09:53:20.000000000 +0200
48     +++ inline.pm       2008-09-02 10:09:02.000000000 +0200
49     @@ -186,7 +186,15 @@
50         }
51
52         if (exists $params{sort} && $params{sort} eq 'title') {
53     -           @list=sort { pagetitle(basename($a)) cmp pagetitle(basename($b)) } @list;
54     +           if (! $params{sorttype} || $params{sorttype} eq 'lexical') {
55     +                   @list=sort { pagetitle(basename($a)) cmp pagetitle(basename($b)) } @list;
56     +           }
57     +           elsif ($params{sorttype} eq 'numeric') {
58     +                   @list=sort { pagetitle(basename($a)) <=> pagetitle(basename($b)) } @list;
59     +           }
60     +           else {
61     +                   return sprintf(gettext("unknown sort type %s"), $params{sorttype});
62     +           }
63         }
64         elsif (exists $params{sort} && $params{sort} eq 'mtime') {
65                 @list=sort { $pagemtime{$b} <=> $pagemtime{$a} } @list;
66     @@ -195,7 +203,7 @@
67                 @list=sort { $pagectime{$b} <=> $pagectime{$a} } @list;
68         }
69         else {
70     -           return sprintf(gettext("unknown sort type %s"), $params{sort});
71     +           return sprintf(gettext("unknown sort key %s"), $params{sort});
72         }
73
74         if (yesno($params{reverse})) {
75
76 ---
77
78 Joey, have you forgotten about that request? ;) --[[Paweł|ptecza]]