splitbrain / dokuwiki-plugin-dw2pdf

A fork of Luigi Micco's PDF export plugin for DokuWiki
http://www.dokuwiki.org/plugin:dw2pdf
55 stars 68 forks source link

properly sort pagenames by namespace. fixes #308 #399

Closed splitbrain closed 4 years ago

splitbrain commented 4 years ago

This ensures pages within the same namespace are put together, with the start page being always first.

I think it would be worth discussing what we actually expect from the natural sort. I would think it should be the same as this, only using natsort as the underlying sort mechanism?

splitbrain commented 4 years ago

Test fails are unrelated and caused by a change in DokuWiki master

Klap-in commented 4 years ago

First quick response: The default start page is $conf['start']. However there is also "Default linking of namespaces" which act as kind of start page as well. https://github.com/splitbrain/dokuwiki/blob/master/inc/pageutils.php#L73 When do we respect these? (e.g. Indexmenu plugin has even option to select the right one).

My first feeling is to ignore other than $conf['start'], because it clutters if people are using them unintentionally.

if start exists, then not foo as startpage and normally sorted:

foo at same level as namespace foo, is automatically solved, if namespaces are sorted as pages. My feeling is that this sorting order is needed to fix the sorting of sub(sub)namespaces(see next point), side effect: this kind of namespace linking is solved as well.

what about combinations of:

and sub-namespace should be

example:

            ['id' => 'start'],
            ['id' => '01_page'],
            ['id' => '10_page'],
            ['id' => 'bar'],
            ['id' => 'bar:start'],
            ['id' => 'bar:01_page'],
            ['id' => 'bar:10_page'],
            ['id' => 'bar:aa_page'],
            ['id' => 'bar:aa_page:detail1'],
            ['id' => 'bar:zz_page'],
            ['id' => 'foo'],
            ['id' => 'foo:start'],
            ['id' => 'foo:01_page'],
            ['id' => 'foo:10_page'],
            ['id' => 'foo:foo'],
            ['id' => 'foo:zz_page'],
            ['id' => 'ns'],
            ['id' => 'ns:ns'],
            ['id' => 'ns:01_page'],
            ['id' => 'ns:10_page'],
            ['id' => 'ns:zz_page'],
            ['id' => 'zz_page'],
splitbrain commented 4 years ago

@Klap-in quick question: how would a namespace without a start page sort into this?

splitbrain commented 4 years ago

I got the sorter to nearly run through your given example. However one thing is a bit tricky. You do not sort up foo:foo because foo:start exists. This is tricky to do in a sort function alone because we only ever compare two given IDs - I have no knowledge about all other IDs. The only way to implement this would be to actually check the existence of the page on disk. It would make testing more complicated, so I would like to avoid it.

There are two options then: always sort the namspace named page to the front, right after start:

Or never do it regardless of the existence of a "proper" start page:

I don't know what to prefer

Klap-in commented 4 years ago

My guess is that a few people know and use the foo:foo as start page for foo. I expect also that always sorting this foo:foo page, will more often be wrong than right.

So to prevent checking existance of these files, it is fine for me to only sort the foo:start page, and to ignore foo:foo during sorting, so sort it just as a normal page.

splitbrain commented 4 years ago

I updated the sorting accordingly. What about:

I think it would be worth discussing what we actually expect from the natural sort. I would think it should be the same as this, only using natsort as the underlying sort mechanism?

Klap-in commented 4 years ago

Ah, did not spot that question. natsort is just sorting the numbers in more logic order, i.e. 1 2 10 14 20 etc (in stead of 1 10 14 2 20), isn't it? I prefer natsort.

As 01 02 10 or 1 2 10 are sorted the same, I don't see problems. Recently at more places in DokuWiki natsort is introduced. For me it feels more logic, and less work for the wiki user.

splitbrain commented 4 years ago

Okay, I removed the difference between the two modes and always sort naturally.