Add a level of indirection to TOC (with PATCH)
|Reported by:||Adriaan de Groot||Owned by:|
I have a whole bunch of wiki pages that together make up the user guide for something. On each page of the user guide, I use the
[[TOC]] macro to provide a table of contents for the whole guide:
This, hoewever, sorts the pages by page name, so in the table of contents the page Advanced shows up before Getting Started. I can fix the ordering by naming the pages in order:
This has a downside: I need to repeat the list of pages everywhere and if I ever add a page (say, UserGuide/Beginner) then I need to go through and add that page all over the place.
You can kind of see this in action in the macro
[[TracGuideToc]], which is a custom TOC that lists the relevant pages in order (probably other stuff, too, but here it's important that it lists pages in a sensible order, not alphabetical by page name, and is used all over the Trac guide).
The attached patch adds a keyword option to the
[[TOC]] macro, allowing it to read the contents of a different page and use that as the page list, as if the contents were listed as individual pages in the macro call itself.
This reads the wiki page !TOC/Guide and adds each line from it to the list of pages to display. Lines starting with # are ignored, so it's possible to put a little documentation / content on the page without affecting the resulting TOCs. Suppose that that wiki page contains the following:
# This is a TOC page for the User Guide UserGuide/GettingStarted UserGuide/Advanced
The lines that don't start with a # are treated as page names, so this is equivalent to
Advantage is that you can change the page !TOC/Guide and all the TOC macros that refer to it through indirect= update as well; this means that the custom index macro can be replaced with a page listing the pages for the TOC in the right order and an indirect= parameter.