index.pl 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # Copyright (C) 2004–2023 Alex Schroeder <alex@gnu.org>
  2. #
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation; either version 3 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. use strict;
  16. use v5.10;
  17. AddModuleDescription('index.pl', 'Index Extension');
  18. our ($q, %Action, %PermanentAnchors, %NearSource);
  19. $Action{'printable-index'} = \&DoPrintableIndex;
  20. sub DoPrintableIndex {
  21. print GetHeader('', T('Index'), '');
  22. my @pages = PrintableIndexPages();
  23. my %hash;
  24. map { push(@{$hash{substr($_,0,1)}}, $_); } @pages;
  25. print '<div class="content printable index">';
  26. print $q->p($q->a({-name=>"top"}),
  27. map { $q->a({-href=>"#$_"}, $_); } sort keys %hash);
  28. foreach my $title (sort keys %hash) {
  29. print '<div class="letter">';
  30. print $q->h2($q->a({-name=>$title}, $title));
  31. foreach my $id (@{$hash{$title}}) {
  32. PrintPage($id);
  33. }
  34. print '</div>';
  35. }
  36. print '</div>';
  37. PrintFooter();
  38. }
  39. # Mostly DoIndex() without the printing.
  40. sub PrintableIndexPages {
  41. my @pages;
  42. push(@pages, AllPagesList()) if GetParam('pages', 1);
  43. push(@pages, keys %PermanentAnchors) if GetParam('permanentanchors', 1);
  44. push(@pages, keys %NearSource) if GetParam('near', 0);
  45. return sort Matched(GetParam('match'), @pages);
  46. }