summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/fortune.pm
blob: 6a12f28fdfa80506d4dd3611da5382329d1989b1 (plain)
  1. #!/usr/bin/perl
  2. # Include a fortune in a page
  3. package IkiWiki::Plugin::fortune;
  4. use warnings;
  5. use strict;
  6. use IkiWiki 2.00;
  7. sub import {
  8. hook(type => "getsetup", id => "fortune", call => \&getsetup);
  9. hook(type => "preprocess", id => "fortune", call => \&preprocess);
  10. }
  11. sub getsetup () {
  12. return
  13. plugin => {
  14. safe => 1,
  15. rebuild => undef,
  16. },
  17. }
  18. sub preprocess (@) {
  19. $ENV{PATH}="$ENV{PATH}:/usr/games:/usr/local/games";
  20. my $f = `fortune 2>/dev/null`;
  21. if ($?) {
  22. error gettext("fortune failed");
  23. }
  24. else {
  25. return "<pre>$f</pre>\n";
  26. }
  27. }
  28. 1