cvs commit: www/scripts manage_news.pl

lizardo at linuxfromscratch.org lizardo at linuxfromscratch.org
Wed Nov 26 10:49:09 PST 2003


lizardo     03/11/26 11:49:09

  Modified:    scripts  manage_news.pl
  Log:
  manage_news.pl: Added "Global configuration" section. Switched to output structure described at http://archives.linuxfromscratch.org/mail-archives/website/2003-November/001748.html
  
  Revision  Changes    Path
  1.21      +71 -34    www/scripts/manage_news.pl
  
  Index: manage_news.pl
  ===================================================================
  RCS file: /home/cvsroot/www/scripts/manage_news.pl,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- manage_news.pl	14 Nov 2003 02:53:35 -0000	1.20
  +++ manage_news.pl	26 Nov 2003 18:49:09 -0000	1.21
  @@ -17,7 +17,7 @@
   # along with this program; if not, write to the Free Software
   # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
   
  -# $Id: manage_news.pl,v 1.20 2003/11/14 02:53:35 lizardo Exp $
  +# $Id: manage_news.pl,v 1.21 2003/11/26 18:49:09 lizardo Exp $
   
   use strict;
   use warnings;
  @@ -31,6 +31,19 @@
   use URI;
   use Pod::Usage;
   
  +#######################
  +# Global configuration
  +
  +my $lfs_url = "/";       # LFS main URL. Set to "/" to make relative URLs
  +
  +# Publishing
  +my $show_content = 1;    # How many items to show fully
  +my $show_link = 5;       # How many items to show as links
  +my $summary_length = 50; # Summary text length (used on <a> "text=" attribute)
  +
  +# End of global configuration
  +##############################
  +
   my $help = 0;
   my $man = 0;
   my $infile = "";
  @@ -74,16 +87,9 @@
       pod2usage("$0\: You need to specify a filename with -i option");
   }
   
  -my $lfs_url = "/";
   my $section = lc(Get_header($mime_entity->head, "section"));
  -die "$0\: $input_name\: Invalid section name: " . $section . "\n" unless $section =~ /^[\w-]+$/;
  -if ($section =~ /^general$/) {
  -    $section = "";
  -}
  -else {
  -    # Create the path to $section for URLs
  -    $section .= "/";
  -}
  +if ($section =~ /^general$/) { $section = "" }
  +else { $section .= "/" };
   
   my $change_urls = sub { return $_[0] };
   
  @@ -169,17 +175,21 @@
       }
   }
   else {
  -    print '</div>' . "\n" .
  -    '<div id="generalnews"><h2>General news</h2>' . "\n" unless $section;
  -    my $count = 0;
  -    foreach my $part ($mime_entity->parts) {
  -        last if $count++ == 2;
  +    print "</div>\n<div id=\"generalnews\"><h2>General news</h2>\n" unless $section;
  +    foreach my $part (splice(@{[$mime_entity->parts]}, 0, $show_content)) {
           print mime2html($part);
       }
  -    my $year = isodate2any(${[$mime_entity->parts]}[0]->head, '%Y');
  -    print "<p><a href=\"${lfs_url}news/${section}${year}/\">Read previous news</a></p>\n";
  -    print '</div>' . "\n" .
  -    '<div id="changelog"><h2>Latest CVS changes:</h2>' . "\n" unless $section;
  +    my @show_as_links = splice(@{[$mime_entity->parts]}, $show_content, $show_link);
  +    if (@show_as_links) {
  +        print "<ul>\n";
  +        foreach my $part (@show_as_links) {
  +            print "\t<li>" . mime2link($part) . "</li>\n";
  +        }
  +        print "</ul>\n";
  +    }
  +    #my $year = isodate2any(${[$mime_entity->parts]}[0]->head, '%Y');
  +    #print "<p><a href=\"${lfs_url}news/${section}${year}/\">Read previous news</a></p>\n";
  +    print "</div>\n<div id=\"changelog\"><h2>Latest CVS changes:</h2>\n" unless $section;
   }
   
   if ($parser->results->errors) {
  @@ -197,7 +207,7 @@
       my ($tag, $attrs) = @_;
   
       if ($$attrs{"href"}) {
  -        $$attrs{"href"} = &$change_urls($$attrs{"href"}) if $$attrs{"href"} !~ /^#/;
  +        $$attrs{"href"} = &$change_urls($$attrs{"href"}) unless $$attrs{"href"} =~ /^#/;
       }
       elsif ($tag eq "img" and $$attrs{"src"}) {
           $$attrs{"src"} = &$change_urls($$attrs{"src"});
  @@ -209,7 +219,7 @@
   
   sub handle_EndTag {
       my ($tag) = @_;
  -
  +    
       if ($buffer =~ /<$tag[^>]*>$/) {
           $buffer =~ s/>$/ \/>/;
       }
  @@ -220,14 +230,11 @@
   
   sub handle_Text {
       my ($text) = @_;
  -
  -    encode_entities($text);
  -    $buffer .= $text;
  +    $buffer .= encode_entities($text);
   }
   
   sub handle_Dec {
       my ($text) = @_;
  -
       $buffer .= $text;
   }
   
  @@ -243,7 +250,7 @@
       "Header contents:\n" . $header->as_string . "\n" unless defined($hdr_content);
       $hdr_content =~ s/^\s*//;
       $hdr_content =~ s/\s*$//;
  -    $hdr_content =~ s/\n$//;
  +    chomp($hdr_content);
       return $hdr_content;
   }
   
  @@ -261,12 +268,10 @@
       }
   }
   
  -# Translate the MIME data to HTML
  +# Translate MIME data to HTML
   sub mime2html {
       my ($mime_part) = @_;
   
  -    my $archive_url = $lfs_url . "news/" . $section .
  -    isodate2any($mime_part->head, '%Y/%m') . ".html";
       my $news_id;
       if (defined($mime_part->head->get("id"))) {
           $news_id = lc(Get_header($mime_part->head, "id"));
  @@ -276,12 +281,43 @@
           $news_id = lc(Get_header($mime_part->head, "title"));
           $news_id =~ s/\W+//g;
       }
  +    my $item_url = $lfs_url . "news/" . $section . isodate2any($mime_part->head, '%Y/%m') . ".html";
  +    my $title = Get_header($mime_part->head, "title");
  +    my $author = Get_header($mime_part->head, "author");
  +    my $date = Get_header($mime_part->head, "date");
  +    my $content = $mime_part->bodyhandle->as_string;
  +
       # Return the XHTML code
  -    return "\t<h3 id=\"$news_id\"><a href=\"$archive_url#$news_id\">" .
  -    Get_header($mime_part->head, "title") . "</a></h3>\n" .
  -    "\t\t<h4>" . Get_header($mime_part->head, "author") . " - " .
  -    Get_header($mime_part->head, "date") . "</h4>\n" .
  -    $mime_part->bodyhandle->as_string . "\n";
  +    return "\t<h3 id=\"$news_id\"><a href=\"$item_url#$news_id\">$title</a></h3>\n" .
  +    "\t\t<h4>$author - $date</h4>\n$content\n";
  +}
  +
  +# Translate MIME data to links pointing to news items
  +sub mime2link {
  +    my ($mime_part) = @_;
  +
  +    my $news_id;
  +    if (defined($mime_part->head->get("id"))) {
  +        $news_id = lc(Get_header($mime_part->head, "id"));
  +    }
  +    else {
  +        # News item ID, created from the news title
  +        $news_id = lc(Get_header($mime_part->head, "title"));
  +        $news_id =~ s/\W+//g;
  +    }
  +    my $item_url = $lfs_url . "news/" . $section . isodate2any($mime_part->head, '%Y/%m') . ".html";
  +    my $title = Get_header($mime_part->head, "title");
  +    my $summary = truncate_text($mime_part->bodyhandle->as_string, $summary_length);
  +
  +    return "<a href=\"$item_url#$news_id\" title=\"$summary\">$title</a>";
  +}
  +
  +sub truncate_text {
  +    my ($text, $length) = @_;
  +
  +    $text =~ s/<[^>]+>//g;
  +    $text =~ s/^\s+//;
  +    return substr(encode_entities($text), 0, $length) . "...";
   }
   
   {
  @@ -314,6 +350,7 @@
           }
           if (/^(\s*)Section:\s+[\w-]+\s*$/i) {
               Error("Invalid space character at start of line $cur_line.") if $1;
  +            Error("Invalid section value at line $cur_line.") unless /^Section:\s+[\w-]+\s*$/;
               $tests{has_section} = 1;
           }
           if (/^(\s*)--(\w+)/) {
  
  
  



More information about the website mailing list