Source

xemacsweb / html2content.pl

Full commit
#! /usr/bin/perl -w

use File::Find;

find( \&changer , ( "content/Releases" ));

sub changer {
  my $file = $_;
  if ( $file =~ '.html' ) {
    my $contents;
    my $author;
    my $title;
    my $main;
    my $newfile =  $file;
    $newfile =~ s/\.html/\.content/ ;
    {
      local $/;
      undef $/;
      open( IN , $file );
      $contents = <IN>;
      close( IN );
    }
    if ( $contents =~ m["author".*?content="(.*?)"]s ) { $author = $1;  }
    else { die( "no author in $file!\n") }

    if ( $contents =~ m[<title>(.*?)</title>] ) { $title = $1; }
    else { die( "no title in $file!\n" ) }

    if ( $contents =~ 
	 m[<!-- content cell -->.*?<td align="left" valign="top">(.*)</td><!-- /content cell -->]s) {
      $main = $1;
    }
    else { die( "no main in $file!\n" ) }

    open( OUT , ">$newfile" );
    print OUT <<EOF;
%title%
$title

%author%
$author

%main%
$main
EOF

  }
}