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