summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/copyright.pm
blob: 0eda81c1c2c0f7cb98497ed2724d387a05b5d2e8 (plain)
  1. # A plugin for ikiwiki to implement adding a footer with copyright information
  2. # based on a default value taken out of a file.
  3. # Copyright © 2007 Thomas Schwinge <tschwinge@gnu.org>
  4. #
  5. # This program is free software; you can redistribute it and/or modify it
  6. # under the terms of the GNU General Public License as published by the
  7. # Free Software Foundation; either version 2, or (at your option) any later
  8. # version.
  9. #
  10. # This program is distributed in the hope that it will be useful, but
  11. # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  12. # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  13. # for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License along
  16. # with this program; if not, write to the Free Software Foundation, Inc.,
  17. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. # A footer with copyright information will be added to every rendered page if
  19. # (a) such a footer isn't present already (see the `meta' plugin's
  20. # ``copyright'' facility) and (b) a file `copyright.html' is found (using the
  21. # same rules as for the sidebar plugin).
  22. #
  23. # The state which page's copyright text was gathered from which source is not
  24. # tracked, so you'll need a full wiki-rebuild if (b)'s files are changed.
  25. #
  26. # You can use wiki links in `copyright.html'.
  27. package IkiWiki::Plugin::copyright;
  28. use warnings;
  29. use strict;
  30. use IkiWiki 2.00;
  31. sub import
  32. {
  33. hook (type => "pagetemplate", id => "copyright", call => \&pagetemplate,
  34. # Run last, as to have the `meta' plugin do its work first.
  35. last => 1);
  36. }
  37. sub pagetemplate (@)
  38. {
  39. my %params = @_;
  40. my $page = $params{page};
  41. my $destpage = $params{destpage};
  42. my $template = $params{template};
  43. if ($template->query (name => "copyright") &&
  44. ! defined $template->param ('copyright'))
  45. {
  46. my $content;
  47. my $copyright_page = bestlink ($page, "copyright") || return;
  48. my $copyright_file = $pagesources{$copyright_page} || return;
  49. #my $pagetype = pagetype ($copyright_file);
  50. # Check if ``$pagetype eq 'html'''?
  51. $content = readfile (srcfile ($copyright_file));
  52. if (defined $content && length $content)
  53. {
  54. $template->param (copyright =>
  55. IkiWiki::linkify ($page, $destpage, $content));
  56. }
  57. }
  58. }
  59. 1