]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - doc/plugins/write.mdwn
Allow hooks to add sorting functions to pagespec_match_list
[git.ikiwiki.info.git] / doc / plugins / write.mdwn
index d94216e17af9de3238e39dfcbffa33ad73cd968f..bfa6617bd554d7f35b2f2f6b253abcf605db1245 100644 (file)
@@ -31,7 +31,7 @@ is accomplished by calling various hooks provided by plugins.
 
 ### compiler
 
-As a compiler, starts by calling the `refresh` hook. Then it checks
+As a compiler, ikiwiki starts by calling the `refresh` hook. Then it checks
 the wiki's source to find new or changed pages. The `needsbuild` hook is
 then called to allow manipulation of the list of pages that need to be
 built. 
@@ -48,10 +48,11 @@ page had previously produced are removed.
 
 ### cgi
 
-The flow between hooks when ikiwiki is run as a cgi is best illistrated by
+The flow between hooks when ikiwiki is run as a cgi is best illustrated by
 an example.
 
-* *Alice browses to a page and clicks Edit.*
+Alice browses to a page and clicks Edit.
+
 * Ikiwiki is run as a cgi. It assigns Alice a session cookie, and,
   by calling the `auth` hooks, sees that she is not yet logged in.
 * The `sessioncgi` hooks are then called, and one of them,
@@ -61,7 +62,9 @@ an example.
   Alice is not signed in.
 * The [[signinedit]] plugin then launches the signin process. A signin
   page is built by calling the `formbuilder_setup` hook.
-* *Alice signs in with her openid.*
+
+Alice signs in with her openid.
+
 * The [[openid]] plugin's `formbuilder` hook sees that an openid was
   entered in the signin form, and redirects to Alice's openid provider.
 * Alice's openid provider calls back to ikiwiki. The [[openid]] plugin
@@ -70,7 +73,9 @@ an example.
   a page.
 * Now all the `canedit` hooks are happy. The [[editpage]] plugin calls
   `formbuilder_setup` to display the page editing form.
-* *Alice saves her change to the page.*
+
+Alice saves her change to the page.
+
 * The [[editpage]] plugin's `formbuilder` hook sees that the Save button
   was pressed, and calls the `checkcontent` and `editcontent` hooks.
   Then it saves the page to disk, and branches into the compiler part
@@ -531,7 +536,7 @@ The data returned is a list of `%config` options, followed by a hash
 describing the option. There can also be an item named "plugin", which
 describes the plugin as a whole. For example:
 
-                return
+               return
                        plugin => {
                                description => "description of this plugin",
                                safe => 1,
@@ -583,6 +588,21 @@ describes the plugin as a whole. For example:
 This hook is used to inject C code (which it returns) into the `main`
 function of the ikiwiki wrapper when it is being generated.
 
+### sort
+
+       hook(type => "sort", id => "foo", call => \&sort_by_foo);
+
+This hook adds an additional [[ikiwiki/pagespec/sorting]] order or overrides
+an existing one. The callback is given two page names as arguments, and
+returns negative, zero or positive if the first page should come before,
+close to (i.e. undefined order), or after the second page.
+
+For instance, the built-in `title` sort order could be reimplemented as
+
+       sub sort_by_title {
+               pagetitle(basename($_[0])) cmp pagetitle(basename($_[1]));
+       }
+
 ## Exported variables
 
 Several variables are exported to your plugin when you `use IkiWiki;`
@@ -731,7 +751,7 @@ By default, dependencies are full content dependencies, meaning that the
 page will be updated whenever anything matching the PageSpec is modified.
 This can be overridden by passing a `deptype` value as the third parameter.
 
-#### `pagespec_match($$;@)`
+### `pagespec_match($$;@)`
 
 Passed a page name, and [[ikiwiki/PageSpec]], returns a true value if the
 [[ikiwiki/PageSpec]] matches the page.
@@ -761,7 +781,7 @@ dependency type from one or more of these keywords:
 
 If multiple types are specified, they are combined.
 
-#### `bestlink($$)`
+### `bestlink($$)`
 
 Given a page and the text of a link on the page, determine which
 existing page that link best points to. Prefers pages under a
@@ -769,7 +789,7 @@ subdirectory with the same name as the source page, failing that
 goes down the directory tree to the base looking for matching
 pages, as described in [[ikiwiki/SubPage/LinkingRules]].
 
-#### `htmllink($$$;@)`
+### `htmllink($$$;@)`
 
 Many plugins need to generate html links and add them to a page. This is
 done by using the `htmllink` function. The usual way to call
@@ -906,6 +926,10 @@ time.
 
 This is the standard gettext function, although slightly optimised.
 
+### `ngettext`
+
+This is the standard ngettext function, although slightly optimised.
+
 ### `urlto($$;$)`
 
 Construct a relative url to the first parameter from the page named by the