#!/usr/bin/perl
my($f, $s, $l, $base, $root, $title, $fname, $month, $xml_src, $html_src);
my($i, $j) = 0;
# used for HOWTOs for which we do not have SGML
#
@_fallback_dates = ();
$_base_path = '/public/vhost/t/tldp/html/HOWTO';
if( $ARGV[0] ne '' ) {
$_base_path = $ARGV[0];
}
# read in template for top part
#
$_template_top = join('', );
close(DATA);
# compute 35 days out, prepare date string
#
$i = 0 + time() - (24 * 60 * 60 * 35);
my(@t_c) = localtime($i);
$i = (($t_c[5])+0) + 1900;
$j = (($t_c[4])+0) + 1;
$month = "$i" .
(length("$j") == 1 ? '0' : '') . "$j" .
(length($t_c[3]) == 1 ? '0' : '') . "$t_c[3]";
# must specify top-level directory; e.g., /public/vhost/t/tldp/html/HOWTO
#
$_base_ht = '/public/ftp/pub/linux/docs/HOWTO/';
$_base_sgml = 'other-formats/docbook/';
$_base_cvs = '/export/sunsite/users/gferg/howto/ldp_cvs/LDP/howto';
$_base_web_cvs = 'http://cvsview.tldp.org/index.cgi/';
# For testing purposes:
#
## &proc_sgml($ARGV[0], "$root/HOWTO-HOWTO/index.html", 'HOWTO-HOWTO');
## exit(0);
# now read/parse the howtos
#
my(@dirs, @howtos, @sbuf) = ();
push(@dirs, $_base_path);
foreach $root (@dirs) {
foreach $f (`cd $root; find -maxdepth 1 -print | sed 's/\\.html//' | sed 's/^\\.\\///' | sort --unique`) {
chop($f);
# ignore these; add to/remove from this list as appropriate
#
if( $f =~ /^\./ || $f =~ /^\!/ || $f =~ /\-[\d]+$/
||
$f eq 'mini' || $f eq 'images' || $f eq 'html_single' || $f eq 'text'
||
$f =~ /README/i || $f =~ /COPYRIGHT/i || $f =~ /^INDEX/i
||
$f =~ /\.gif$/ || $f =~ /\.tar$/
||
$f =~ /\.gz$/ || $f =~ /\.bz/ ) {
next;
}
if( -f "$root/${f}/index.html" ) {
if( -s "$root/${f}/index.html" < 300 ) {
next; # redirect files and such...
}
}
elsif( -f "$root/${f}.html" ) {
if( -s "$root/${f}.html" < 300 ) {
next; # redirect files and such...
}
}
# find source file
#
$xml_src = '';
$html_src = '';
if( -f "$_base_cvs/linuxdoc/${f}.sgml" ) {
$xml_src = "$_base_cvs/linuxdoc/${f}.sgml";
$html_src = "$root/${f}.html";
} elsif( -f "$_base_cvs/docbook/${f}.xml" ) {
$xml_src = "$_base_cvs/docbook/${f}.xml";
$html_src = "$root/${f}/index.html";
} elsif( -f "$_base_cvs/docbook/${f}.sgml" ) {
$xml_src = "$_base_cvs/docbook/${f}.sgml";
$html_src = "$root/${f}/index.html";
} elsif( -f "$_base_cvs/docbook/${f}/${f}.xml" ) {
$xml_src = "$_base_cvs/docbook/${f}/${f}.xml";
$html_src = "$root/${f}/index.html";
} elsif( -f "$_base_cvs/docbook/${f}/${f}.sgml" ) {
$xml_src = "$_base_cvs/docbook/${f}/${f}.sgml";
$html_src = "$root/${f}/index.html";
} elsif( -f "$_base_cvs/linuxdoc/${f}/${f}.sgml" ) {
$xml_src = "$_base_cvs/linuxdoc/${f}/${f}.sgml";
$html_src = "$root/${f}.html";
} elsif( -f "$_base_cvs/linuxdoc/archived/${f}.sgml" ) {
$xml_src = "$_base_cvs/linuxdoc/archived/${f}.sgml";
$html_src = "$root/${f}.html";
} elsif( -f "$_base_cvs/docbook/archived/${f}.sgml" ) {
$xml_src = "$_base_cvs/docbook/archived/${f}.sgml";
$html_src = "$root/${f}/index.html";
}
if( $xml_src ne '' ) {
&proc_sgml($xml_src, $html_src, $f);
} else {
# fallback to processing the HTML
#
print "mk_sortedht: no SGML for $f, using the HTML file\n";
&proc_html("$root/${f}.html", $f);
}
}
}
#
# 0 1 2 3 4 5 6 7 8
# date | type | title | html | plain | pdf | author | email | version |
#
# 9 10 11 12 13 14
# title | fname_lc | fname | html (tar) | pluckerdb | cvs
#
# now we need to sort & output accordingly
#
@howtos = reverse(sort(@howtos));
# the data file...
#
open(DF, "> /public/vhost/t/tldp/html/howto.d/sorted_howtos") || die "cannot open:$!\n";
foreach $s (@howtos) {
$s =~ s/\t/\ /g;
$s =~ s/<[;]*//gi;
$s =~ s/&[;]*/\&/gi;
$s =~ s/&lowbar[;]/_/gi;
$s =~ s/[\s\ ]+$//g;
$s =~ s/^[\s\ ]+//g;
$s =~ s/\[\d\]//g;
$s =~ s/\r/\ /g;
$s =~ s/[\ ]{2,}/\ /g;
@sbuf = split(/\|/, $s);
print DF "$sbuf[0]\t$sbuf[1]\t$sbuf[2]\t$sbuf[3]\t$sbuf[6] $sbuf[7]\n";
}
close(DF);
system("gzip -f /public/vhost/t/tldp/html/howto.d/sorted_howtos");
system("chmod 664 /public/vhost/t/tldp/html/howto.d/sorted_howtos.gz");
system("chgrp ldp /public/vhost/t/tldp/html/howto.d/sorted_howtos.gz");
# sorted file number 1 - by modify date / 30 day window
#
&print_detail("/public/vhost/t/tldp/html/sorted_howtos.html");
# sorted file number 2 - by modify date - all list
#
&print_detail("/public/vhost/t/tldp/html/sorted_howtos_full.html");
# sorted file number 3 - by title
#
@sbuf = map { $_->[0] }
sort { $a->[10] cmp $b->[10] }
map { [ $_, (split /\|/)[0,1,2,3,4,5,6,7,8,9,10,11,12,13] ] } @howtos;
@howtos = @sbuf;
&print_detail("/public/vhost/t/tldp/html/sorted_howtos_title.html");
# sorted file number 4 - by filename
#
@sbuf = map { $_->[0] }
sort { $a->[11] cmp $b->[11] }
map { [ $_, (split /\|/)[0,1,2,3,4,5,6,7,8,9,10,11,12,13] ] } @howtos;
@howtos = @sbuf;
&print_detail("/public/vhost/t/tldp/html/sorted_howtos_quick.html");
exit(0);
#
#
#
sub print_detail {
my($f) = @_;
my($s,$tmp_str);
my(@sbuf) = ();
open(HTFILE, "> $f") || die "cannot open $f: $!\n";
$s = $_template_top;
if ($f =~ /sorted_howtos\.html$/) {
$s =~ s/Sorted\ HOWTOs/Recent Updates/g;
}
print HTFILE "$s\n",
"\n
| \n", "updated | \n", "\n", "title / available formats | \n", "\n", "author(s) | \n", "
| \n",
$sbuf[0], " v", $sbuf[8], " | \n",
"\n",
"", $sbuf[11], " : ", $sbuf[2], " \n", ($sbuf[3] ne '' ? "html (multiple)" : "html (multiple)"), " | ", ($html_single ne '' ? "html (single)" : "html (single)"), " | ", ($sbuf[12] ne '' ? "html (tar)" : "html (tar)"), " | ", ($sbuf[4] ne '' ? "text" : "text"), " | ", ($sbuf[5] ne '' ? "PDF" : "PDF"), " | ", ($sbuf[14] ne '' ? "source (cvs)" : "source (cvs)"), " | ", ($sbuf[13] ne '' ? "pluckerDB" : "PluckerDB"), "\n | \n",
"\n", ($sbuf[6] ne '' ? $sbuf[6] : " "), " | \n
",
"\n
\n",
"\n\n",
"\n