cvs commit: www/scripts manage_news.pl

lizardo at linuxfromscratch.org lizardo at linuxfromscratch.org
Sun Nov 30 07:22:38 PST 2003


lizardo     03/11/30 08:22:38

  Modified:    scripts  manage_news.pl
  Log:
  manage_news.pl: Fix broken URLs on news archives.
  
  Revision  Changes    Path
  1.26      +24 -8     www/scripts/manage_news.pl
  
  Index: manage_news.pl
  ===================================================================
  RCS file: /home/cvsroot/www/scripts/manage_news.pl,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- manage_news.pl	29 Nov 2003 19:20:56 -0000	1.25
  +++ manage_news.pl	30 Nov 2003 15:22:38 -0000	1.26
  @@ -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.25 2003/11/29 19:20:56 lizardo Exp $
  +# $Id: manage_news.pl,v 1.26 2003/11/30 15:22:38 lizardo Exp $
   
   use strict;
   use warnings;
  @@ -97,6 +97,8 @@
   else { $section .= "/" };
   
   my $base_url = "";
  +# Flag to convert relative URLs on news items for archiving
  +my $CONVERT_URLS = 0;
   
   if ($archive_under) {
       # News items' dates (%dates->year->month)
  @@ -157,8 +159,10 @@
           my $archive_file = $archive_under . "/" . $section . isodate2any($part->head, '%Y/%m') . ".html";
           $base_url = $lfs_url . "news/" . $section . isodate2any($part->head, '%Y') . "/";
           open(NEWS, ">>$archive_file") or die "$0\: Could not open $archive_file" . ": $!\n";
  +        $CONVERT_URLS = 1;
           $html_p->parse(mime2html($part));
           $html_p->eof;
  +        $CONVERT_URLS = 0;
           print NEWS $buffer . "\n\n";
           $buffer = "";
           close NEWS;
  @@ -213,10 +217,22 @@
       my ($tag, $attrs) = @_;
   
       if ($$attrs{"href"}) {
  -        $$attrs{"href"} = change_urls($$attrs{"href"}) unless $$attrs{"href"} =~ /^#/;
  +        if ($CONVERT_URLS) {
  +            my $old_base_url = $section ? $lfs_url . $section : $lfs_url . "dummy_section/";
  +            $$attrs{"href"} = change_urls($$attrs{"href"}, $old_base_url) unless $$attrs{"href"} =~ /^#/;
  +        }
  +        else {
  +            $$attrs{"href"} = change_urls($$attrs{"href"}) unless $$attrs{"href"} =~ /^#/;
  +        }
       }
       if ($$attrs{"src"}) {
  -        $$attrs{"src"} = change_urls($$attrs{"src"});
  +        if ($CONVERT_URLS) {
  +            my $old_base_url = $section ? $lfs_url . $section : $lfs_url . "dummy_section/";
  +            $$attrs{"src"} = change_urls($$attrs{"src"}, $old_base_url);
  +        }
  +        else {
  +            $$attrs{"src"} = change_urls($$attrs{"src"});
  +        }
       }
       $buffer .= "<$tag";
       $buffer .= " $_=\"$$attrs{$_}\"" foreach (keys %$attrs);
  @@ -330,16 +346,16 @@
   
   # Make URLs relative or absolute (see $relative_urls)
   sub change_urls {
  -    my ($url) = @_;
  -
  -    $base_url = $lfs_url unless $base_url;
  +    my $url = shift @_;
  +    my $old_base_url;
  +    $old_base_url = $base_url unless $old_base_url = shift @_;
   
       # "scheme" returns undef if $url is relative
       if ($relative_urls and !defined(URI->new($url)->scheme)) {
  -        return URI->new($url)->abs($base_url)->rel($base_url);
  +        return URI->new($url)->abs($old_base_url)->rel($base_url);
       }
       else {
  -        return URI->new($url)->abs($base_url);
  +        return URI->new($url)->abs($old_base_url);
       }
   }
   
  
  
  



More information about the website mailing list