summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/haiku.pm
blob: 35208e56cfcc307ba95f23555ec537d1b78859e7 (plain)
  1. #!/usr/bin/perl
  2. # haiku generator plugin
  3. package IkiWiki::Plugin::haiku;
  4. use warnings;
  5. use strict;
  6. use IkiWiki 2.00;
  7. sub import { #{{{
  8. hook(type => "preprocess", id => "haiku", call => \&preprocess);
  9. } # }}}
  10. sub preprocess (@) { #{{{
  11. my %params=@_;
  12. my $haiku;
  13. eval q{use Coy};
  14. if ($@ || ! Coy->can("Coy::with_haiku")) {
  15. my @canned=(
  16. "The lack of a Coy:
  17. No darting, subtle haiku.
  18. Instead, canned tuna.
  19. ",
  20. "apt-get install Coy
  21. no, wait, that's not quite it
  22. instead: libcoy-perl
  23. ",
  24. "Coyly I'll do it,
  25. no code, count Five-Seven-Five
  26. to make a haiku.
  27. ",
  28. );
  29. $haiku=$canned[rand @canned];
  30. }
  31. else {
  32. $haiku=Coy::with_haiku($params{hint} ? $params{hint} : $params{page});
  33. # trim off other text
  34. $haiku=~s/\s+-----\n//s;
  35. $haiku=~s/\s+-----.*//s;
  36. }
  37. $haiku=~s/^\s+//mg;
  38. $haiku=~s/\n/<br>\n/mg;
  39. return "\n\n<blockquote>$haiku</blockquote>\n\n";
  40. } # }}}
  41. 1