#!/usr/bin/perl
#
# $Id: fix-pod-xhtml,v 1.1.1.1 2005/07/06 09:38:37 gully Exp $
#
# Format XHTML generated by pod2html (via tidy) for websites
#
# Usage: pod2html ... MODULE.pm | tidy ... | fix-pod-xhtml OUTPUT-FILE
#
# Copyright (C) 2001-2004 David Beckett - http://purl.org/net/dajobe/
# Institute for Learning and Research Technology - http://www.ilrt.bris.ac.uk/
# University of Bristol - http://www.bristol.ac.uk/
#

use strict;
use File::Basename;

my $progname=basename $0;

my $main_title="Redland RDF Application Framework";

die "USAGE: $progname OUTPUT-FILE\n" if @ARGV < 1;

my $doc_title;

my($file)=@ARGV;

my($pod_rdf_rel)=($file =~ m%^pod/RDF/%) ? '../' : '';
my($pod_rdf_redland_rel)=($file =~ m%^pod/RDF/Redland/%) ? '' : 'Redland/';

open(OUT, ">$file") or die "$progname: Cannot create $file - $!\n";
print OUT qq{<?xml version="1.0" encoding="iso-8859-1"?>\n};
open(IN, "-");
while(<IN>) {
  if(m%<title>(.*?)</title>%) {
    $doc_title=$1;
    $doc_title =~ s/^(.*) - Redland (.*) Class$/Perl $1 Class/;
    s%<title>(.*?)</title>%<title>$main_title - $doc_title</title>%;
  }

  next if /^\s*<link|meta/i;

  s'(id|name)="([^"]+)"'my($a,$v)=($1,$2); $v=~ s/%/_/g; qq{$a="$v"}'eg;

  s%<h1>%<h2>%; s%</h1>%</h2>%;
  s%<hr />%%;

  s%href="/docs/pod/RDF/Redland/([^"]+)"%href="$pod_rdf_redland_rel$1"%g;
  s%href="/docs/pod/RDF/([^"]+)"%href="$pod_rdf_rel$1"%g;

  s%^<body[^>]*>%<body>\n\n<h1 style="text-align:center">$main_title - $doc_title</h1>\n\n%;

  s%^<p><a id="__index__".*</p>%%;

  my $year=1900+(localtime)[5];
  print OUT <<"EOT" if m%^</body>%;
<hr />

<p>Copyright 2000-$year <a href="http://purl.org/net/dajobe/">Dave Beckett</a>, <a href="http://www.ilrt.bris.ac.uk/">Institute for Learning and Research Technology</a>, <a href="http://www.bristol.ac.uk/">University of Bristol</a></p>

EOT
  print OUT;
}
close(IN);
close(OUT);
