headlines.pl 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # Copyright (C) 2004 Alex Schroeder <alex@emacswiki.org>
  2. # Copyright (C) 2005 Ingo Belka <grimmen@mvnet.de>
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 3 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. use strict;
  17. use v5.10;
  18. AddModuleDescription('headlines.pl', 'Headlines Extension');
  19. our (@MyRules);
  20. our ($HeadlineNumber);
  21. push(@MyRules, \&HeadlinesRule);
  22. # Include this page on every page:
  23. $HeadlineNumber = 20;
  24. sub HeadlinesRule {
  25. if (m/\G(\&lt;headlines(:(\d+))?\&gt;)/cgi) {
  26. if (($3) and ($3>0)) {$HeadlineNumber = $3;};
  27. Clean(CloseHtmlEnvironments());
  28. Dirty($1);
  29. HeadlinesPrint();
  30. return AddHtmlEnvironment('p');
  31. }
  32. return;
  33. }
  34. sub HeadlinesPrint {
  35. my @pages = (grep(/^\d\d\d\d-\d\d-\d\d_.+/, AllPagesList()));
  36. @pages = sort {$b cmp $a} @pages;
  37. @pages = @pages[0 .. $HeadlineNumber - 1] if $#pages >= $HeadlineNumber;
  38. my $current_date;
  39. if (@pages) {
  40. print '<dl class="headlines">';
  41. foreach my $page (@pages) {
  42. if ($page =~ /^(\d\d\d\d-\d\d-\d\d)_(.+)/) {
  43. my ($date, $title) = ($1, $2);
  44. $title =~ s/_/ /g;
  45. print '<dt class="headlinesdate">' . $date . '</dt>' unless $date eq $current_date;
  46. $current_date = $date;
  47. print '<dd>' . ScriptLink($page, $title, 'headlineslink') . '</dd>';
  48. }
  49. }
  50. print '</dl>';
  51. }
  52. }