headlines.pl 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 2 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, write to the
  16. # Free Software Foundation, Inc.
  17. # 59 Temple Place, Suite 330
  18. # Boston, MA 02111-1307 USA
  19. use strict;
  20. use v5.10;
  21. AddModuleDescription('headlines.pl', 'Headlines Extension');
  22. our (@MyRules);
  23. our ($HeadlineNumber);
  24. push(@MyRules, \&HeadlinesRule);
  25. # Include this page on every page:
  26. $HeadlineNumber = 20;
  27. sub HeadlinesRule {
  28. if (m/\G(\&lt;headlines(:(\d+))?\&gt;)/cgi) {
  29. if (($3) and ($3>0)) {$HeadlineNumber = $3;};
  30. Clean(CloseHtmlEnvironments());
  31. Dirty($1);
  32. HeadlinesPrint();
  33. return AddHtmlEnvironment('p');
  34. }
  35. return;
  36. }
  37. sub HeadlinesPrint {
  38. my @pages = (grep(/^\d\d\d\d-\d\d-\d\d_.+/, AllPagesList()));
  39. @pages = sort {$b cmp $a} @pages;
  40. @pages = @pages[0 .. $HeadlineNumber - 1] if $#pages >= $HeadlineNumber;
  41. my $current_date;
  42. if (@pages) {
  43. print '<dl class="headlines">';
  44. foreach my $page (@pages) {
  45. if ($page =~ /^(\d\d\d\d-\d\d-\d\d)_(.+)/) {
  46. my ($date, $title) = ($1, $2);
  47. $title =~ s/_/ /g;
  48. print '<dt class="headlinesdate">' . $date . '</dt>' unless $date eq $current_date;
  49. $current_date = $date;
  50. print '<dd>' . ScriptLink($page, $title, 'headlineslink') . '</dd>';
  51. }
  52. }
  53. print '</dl>';
  54. }
  55. }