Gossamer Forum
Home : General : Perl Programming :

"how can i generates static HTML for cgi pages"

Quote Reply
"how can i generates static HTML for cgi pages"
How can I generates static HTML files of all the navigation categories in the cgi directory database on my website.Database using "ID" number instead of using text. All generated files are shoud be fully functional and "navigable" and will work exactly like the normal navigation pages dynamically generate by the scripts.

The purpose of this is so that I can generate all my cgi pages, and submit them to search engines that do not spider .cgi pages.

Any one could hep is appreciated.
Quote Reply
Re: [dooballoh] "how can i generates static HTML for cgi pages" In reply to
What I've done is something like this (in DBman):

For all html routines that may print out to the screen OR to a static file (html_page_top, html_page_bottom, html_record), change the print statements so that they merely append output to a scalar. Depending on a value passed to the routine, the final output is then either printed to the screen or to a file.



example:

sub html_page_top {

my $printvar = shift;

my $output = qq|<html><head><title>Test page</title></head><body>|;

if ($printvar eq "display") { print qq|$output|;}

else {return ($output);}

}

sub html_record {

my $printvar = shift;

my %rec = @_;

my $output = qq|$rec{'field'}, $rec{'anotherfield'}<br>|;

if ($printvar eq "display") { print qq|$output|;}

else {return ($output);}

}

sub create_static_file {

my $id = $in{'ID'};

my %rec = &get_record($id);

my $output = &html_page_top("print");

$output .= &html_record("print", %rec);

$output .= &html_page_bottom("print");

open (FILE, ">whateverfilenameyouwant") || &cgierr ("Can't write to whateverfilenameyouwant: $!");

print FILE "$output";

close(FILE);

}

... and add html_page_bottom in the same style as html_page_top.

This is the easy part - if you just want to print one record per page.

What gets more complex is if you want to print different forms of query results to static pages.

I'm currently developing something like this, and it's not that simple. I created a static file database where query-strings for individual queries are stored (there's a form input routine for this). When the static file is created, the script takes the parameters from that query-string, does an internal search and prints out results to the file. When you change formatting options in html_page_top, you can then simply recreate all query-based pages automatically, you don't have to go through each file.

There's lots of other things that need to be taken care of, but maybe this gives you some ideas.
kellner

Last edited by:

kellner: Feb 8, 2002, 2:14 PM