sub _customize_title_page()

in lib/ES/Util.pm [272:302]


sub _customize_title_page {
#===================================
    my ( $index, $html_file, $single ) = @_;
    my $index_basename = $index->basename;

    (my $custom_title_page = $index_basename) =~ s/(\.x)?\.a(scii)?doc$/-custom-title-page.html/ || die;
    $custom_title_page = $index->parent->file( $custom_title_page );

    (my $extra_title_page = $index_basename) =~ s/(\.x)?\.a(scii)?doc$/-extra-title-page.html/ || die;
    $extra_title_page = $index->parent->file( $extra_title_page );

    if ( -e $custom_title_page ) {
        die "Using a custom title page is incompatible with --single" if $single;
        die "Cannot have both custom and extra title pages for the same source file" if -e $extra_title_page;

        my $custom_contents = $custom_title_page->slurp( iomode => '<:encoding(UTF-8)' );
        my $contents = $html_file->slurp( iomode => '<:encoding(UTF-8)' );
        $contents =~ s|<!--START_TOC-->.*<!--END_TOC-->|$custom_contents|sm or
            die "Couldn't set custom contents in file";
        $html_file->spew( iomode => '>:utf8', $contents );
    }
    elsif ( -e $extra_title_page ) {
        my $extra_contents = $extra_title_page->slurp( iomode => '<:encoding(UTF-8)' );
        my $contents = $html_file->slurp( iomode => '<:encoding(UTF-8)' );
        # Wrapping the extra in a div is a relic of docbook. But we're trying
        # to emulate docbook so here we are.
        $contents =~ s|</h1></div>|</h1></div>\n<div>\n$extra_contents\n</div>| or
            die "Couldn't add extra-title-page to $contents";
        $html_file->spew( iomode => '>:utf8', $contents );
    }
}