Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Find and convert all pod to html

by ryddler (Monk)
on Jan 30, 2001 at 01:33 UTC ( [id://55079]=sourcecode: print w/replies, xml ) Need Help??
Category: Utility Scripts
Author/Contact Info ryddler ryddler@cu-online.com
Description: Searches the site and lib directories on an ActiveState install for any POD that isn't in HTML format and converts it. Rebuilds HTML TOC after conversion. A logfile is kept to track additions.
#! perl -w

###########################################################
# Just a quick and dirty utility to search for POD that 
# hasn't been converted to HTML by an install or was simply
# unzipped or copied into the site or lib subdirectories. 
# Checks to see if an existing .html version of the POD 
# exists, if not converts it to HTML. After conversion the 
# AS Docs TOC is rebuilt so that all newly added docs are listed.

use strict;
use Pod::Html;
use Pod::Find qw(pod_find);
use ActivePerl::DocTools;
use File::Path;

my $infile_path_root = "c:/perl";
my $outfile_path_root = "c:/perl/html";
my $logfile = "c:/perl/allpod.txt";

open LOGFILE, ">>$logfile" || die "couldn't open LOGFILE $logfile\n";
&search_for_pod;
print LOGFILE "-" x 60, "\n";
close LOGFILE;
ActivePerl::DocTools::WriteTOC();

sub search_for_pod {
    my %pods = pod_find({ -verbose => 0, -inc => 1 });
    foreach(sort keys %pods) {
        convert_pod($_);
    }
}

sub convert_pod {
    my $podfile = shift;
    $podfile =~ s#\\#/#g;
    if ($podfile =~ m!$infile_path_root/(.*)/(\w+)\.p.+$!i) {
        my $path = $1;
        my $name = $2;
        if (! -e "$outfile_path_root/$path/$name\.html") {
            mkpath("$outfile_path_root/$path");
            pod2html( "--infile=$podfile",
                "--outfile=$outfile_path_root/$path/$name.html",
                "--podroot=$infile_path_root",
                "--podpath=site/lib:lib",
            );
            print LOGFILE "-- Created $outfile_path_root/$path/$name.h
+tml\n";
        }
    }
}
Replies are listed 'Best First'.
Re: Find and convert all pod to html
by Anonymous Monk on Apr 09, 2019 at 23:39 UTC
    Thank you for this script. I am using strawberry perl and cannot install ActivePerl::DocTools over cpan. So I deciced to change the script a little and coded my own TOC-file creation:
    use strict; use Pod::Html; use Pod::Find qw(pod_find); use File::Path; my $infile_path_root = "C:/MySw/Strawberry5.28x64/perl"; my $outfile_path_root = "C:/MySw/Strawberry5.28x64/html"; my $alternativeIndexFile = "$outfile_path_root/my_alternative_index.ht +ml"; my $logfile = "C:/MySw/Strawberry5.28x64/allpod.txt"; my %pods = pod_find({ -verbose => 0, -inc => 1 }); my (@sorted); foreach my $podfile (keys %pods) { $podfile =~ s#\\#/#g; my ($path,$name) = ($podfile =~ m!^$infile_path_root(/.+)?/([^\/]+ +)\.(pod|pm|pl)$!io); my (@depth) = ($path =~ /(\/)/go); my $depth = scalar @depth; my $sorted = sprintf("%010d%-s",$depth,$podfile); push(@sorted,$sorted); } open INDEX, ">$alternativeIndexFile" || die "Cannot open $alternativeI +ndexFile\n"; print INDEX "<html><head><title>Strawberry Perl Documentation - Versio +n 5.28</title></head>\n"; print INDEX "<body>\n<blockquote>\n<h2>Strawberry Perl Documentation - + Version 5.28</h2>\n"; print INDEX "<h3>Table of Content</h3>\n"; open LOG, ">$logfile" || die "Cannot open $logfile\n"; pmpod2html(); close(LOG); print INDEX "</blockquote>\n</body></html>\n"; close(INDEX); sub pmpod2html { my ($prepath,$predepth); foreach my $podfile (sort @sorted) { $podfile =~ s/^\d{10}//o; my ($path,$name) = ($podfile =~ m!^$infile_path_root(/.+)?/([^ +\/]+)\.(pod|pm|pl)$!io); $path =~ s/^\///o; my (@depth) = ($path =~ /(\/)/go); my $depth = scalar @depth; print INDEX '</blockquote>' x$predepth . "\n" . '<blockquote>' + x$depth . "\n\n" . "<b>$path</b><br>\n" if($prepath ne $path); if (! -e "$outfile_path_root/$path/$name\.html") { mkpath("$outfile_path_root/$path"); pod2html( "--infile=$podfile", "--outfile=$outfile_path_root/$path/$name.html", "--podroot=$infile_path_root", "--podpath=lib:site:vendor", ); my ($htmlfile); open(IN,"<$outfile_path_root/$path/$name.html") || die "Ca +nnot open $outfile_path_root/$path/$name.html\n"; while(<IN>) { $htmlfile .= $_; } my ($title) = ($htmlfile =~ /<title>\s*(.+?)\s*<\/title>/i +os); close(IN); print LOG "$podfile\n"; if($title) { print INDEX "$title: <a href=\"$path/$name.ht +ml\">$name.html</a><br>\n"; } else { print INDEX "<a href=\"$path/$name.html\">$name.htm +l</a><br>\n"; } } $prepath = $path; $predepth = $depth; } }
Re: Find and convert all pod to html
by $code or die (Deacon) on Jan 31, 2001 at 14:36 UTC
      After posting the script above I realized that pod2html could not set the cross referencing between the html files correctly. Depending on the number of subdirectories it needs additionally "../../.." in href for relative referencing. Just one look to the possible parameters of pod2html showed that it needed the parameter "--htmldir=name". So this is the final version with creating a TOC-file and correct referencing:
      use strict; use Pod::Html; use Pod::Find qw(pod_find); use File::Path; my $podroot = "C:/MySw/Strawberry5.28x64/perl"; my $htmldir = "C:/MySw/Strawberry5.28x64/html"; my $indexhtml = "$htmldir/my_alternative_index.html"; my $logfile = "C:/MySw/Strawberry5.28x64/allpod.txt"; if(!-e $htmldir) { mkdir($htmldir) || die "Cannot mkdir $htmldir !!\n" +; } my %pods = pod_find({ -verbose => 0, -inc => 1 }); my (@sorted); foreach my $podfile (keys %pods) { $podfile =~ s#\\#/#g; my ($path,$name) = ($podfile =~ m!^$podroot(/.+)?/([^\/]+)\.(pod|p +m|pl)$!i); my (@depth) = ($path =~ /(\/)/go); my $depth = scalar @depth; my $sorted = sprintf("%010d%-s",$depth,$podfile); push(@sorted,$sorted); } open IDX, ">$indexhtml" || die "Cannot open $indexhtml\n"; print IDX "<html><head><title>Perl Documentation - Ver 5.28</title></h +ead>\n"; print IDX "<body>\n<blockquote>\n<h2>Perl Documentation - Ver 5.28</h2 +>\n"; print IDX "<h3>Table of Content</h3>\n"; open LOG, ">$logfile" || die "Cannot open $logfile\n"; pmpod2html(); close(LOG); print IDX "</blockquote>\n</body></html>\n"; close(IDX); sub pmpod2html { my ($prepath,$predepth); foreach my $podfile (sort @sorted) { $podfile =~ s/^\d{10}//o; my ($path,$name) = ($podfile =~ m!^$podroot(/.+)?/([^\/]+)\.(p +od|pm|pl)$!i); $path =~ s/^\///o; my (@depth) = ($path =~ /(\/)/go); my $depth = scalar @depth; print IDX '</blockquote>' x$predepth . "\n\n" . '<blockquote>' + x$depth . "\n" . "<b>$path</b><br>\n" if($prepath ne $path); if (! -e "$htmldir/$path/$name\.html") { mkpath("$htmldir/$path"); pod2html( "--infile=$podfile", "--outfile=$htmldir/$path/$name.html", "--podroot=$podroot", "--podpath=lib:site:vendor", "--htmldir=$htmldir", ); my ($htmlfile); open(IN,"<$htmldir/$path/$name.html") || die "Cannot open +$htmldir/$path/$name.html\n"; while(<IN>) { $htmlfile .= $_; } my ($title) = ($htmlfile =~ /<title>\s*(.+?)\s*<\/title>/i +os); close(IN); print LOG "$podfile\n"; if($title) { print IDX "$title: <a href=\"$path/$name.html\">$name. +html</a><br>\n"; } else { print IDX "<a href=\"$path/$name.html\">$name.html< +/a><br>\n"; } } $prepath = $path; $predepth = $depth; } }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: sourcecode [id://55079]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2024-04-19 05:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found