X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/d5e65e582a34ae2494fee493ddcb2b959e4a4bce..2f33f294d95def3c50a467c5b5b9c5f5cae9e5fb:/doc/plugins/write.mdwn diff --git a/doc/plugins/write.mdwn b/doc/plugins/write.mdwn index 22bd5d114..58c04d97a 100644 --- a/doc/plugins/write.mdwn +++ b/doc/plugins/write.mdwn @@ -128,26 +128,34 @@ of a plugin. hook(type => "preprocess", id => "foo", call => \&preprocess); -Replace "foo" with the command name that will be used inside brackets for -the preprocessor directive. - -Each time the directive is processed, the referenced function (`preprocess` -in the example above) is called, and is passed named parameters. A "page" -parameter gives the name of the page that embedded the preprocessor -directive, while a "destpage" parameter gives the name of the page the -content is going to (different for inlined pages), and a "preview" -parameter is set to a true value if the page is being previewed. All -parameters included in the directive are included as named parameters as -well. Whatever the function returns goes onto the page in place of the +Replace "foo" with the command name that will be used for the preprocessor directive. -An optional "scan" parameter, if set to a true value, makes the hook be -called during the preliminary scan that ikiwiki makes of updated pages, -before begining to render pages. This parameter should be set to true if -the hook modifies data in `%links`. Note that doing so will make the hook -be run twice per page build, so avoid doing it for expensive hooks. (As an -optimisation, if your preprocessor hook is called in a void contets, you -can assume it's being run in scan mode.) +Each time the directive is processed, the referenced function (`preprocess` +in the example above) is called. Whatever the function returns goes onto +the page in place of the directive. Or, if the function aborts using +`error()`, the directive will be replaced with the error message. + +The function is passed named parameters. First come the parameters set +in the preprocessor directive. These are passed in the same order as +they're in the directive, and if the preprocessor directive contains a bare +parameter (example: `\[[!foo param]]`), that parameter will be passed with +an empty value. + +After the parameters from the preprocessor directive some additional ones +are passed: A "page" parameter gives the name of the page that embedded the +preprocessor directive, while a "destpage" parameter gives the name of the +page the content is going to (different for inlined pages), and a "preview" +parameter is set to a true value if the page is being previewed. + +If `hook` is passed an optional "scan" parameter, set to a true value, this +makes the hook be called during the preliminary scan that ikiwiki makes of +updated pages, before begining to render pages. This should be done if the +hook modifies data in `%links`. Note that doing so will make the hook be +run twice per page build, so avoid doing it for expensive hooks. (As an +optimisation, if your preprocessor hook is called in a void context, you +can assume it's being run in scan mode, and avoid doing expensive things at +that point.) Note that if the [[htmlscrubber]] is enabled, html in [[ikiwiki/PreProcessorDirective]] output is sanitised, which may limit what @@ -348,6 +356,15 @@ This hook is called whenever ikiwiki normally saves its state, just before the state is saved. The function can save other state, modify values before they're saved, etc. +## renamepage + + hook(type => "renamepage", id => "foo", call => \&renamepage); + +This hook is called by the [[plugins/rename]] plugin when it renames +something. The hook is passed named parameters: `page`, `oldpage`, +`newpage`, and `content`, and should try to modify the content to reflect +the name change. For example, by converting links to point to the new page. + ## Plugin interface To import the ikiwiki plugin interface: @@ -573,12 +590,15 @@ time. This is the standard gettext function, although slightly optimised. -#### `urlto($$)` +#### `urlto($$;$)` Construct a relative url to the first parameter from the page named by the second. The first parameter can be either a page name, or some other destination file, as registered by `will_render`. +If the third parameter is passed and is true, an absolute url will be +constructed instead of the default relative url. + #### `targetpage($$)` Passed a page and an extension, returns the filename that page will be @@ -635,4 +655,5 @@ when imported, populate `$IkiWiki::Setup::raw_setup` with a reference to a hash containing all the config items. By the way, to parse a ikiwiki setup file, a program just needs to -do something like `use IkiWiki::Setup; my %setup=IkiWiki::Setup::load($filename)` +do something like: +`use IkiWiki::Setup; my %setup=IkiWiki::Setup::load($filename)`