summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/fortune.pm
blob: f481c7eacea7240b3b8032311d3c4e9b307bfe63 (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 3.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. section => "widget",
  17. },
  18. }
  19. sub preprocess (@) {
  20. $ENV{PATH}="$ENV{PATH}:/usr/games:/usr/local/games";
  21. my $f = `fortune 2>/dev/null`;
  22. if ($?) {
  23. error gettext("fortune failed");
  24. }
  25. else {
  26. return "<pre>$f</pre>\n";
  27. }
  28. }
  29. 1