I wrote a really bad script which lets you add in a file in the template directory and then output a static parsed page in an arbitrary folder, which is determined by the prefix specified in the script. I'm reluctant to post it because it's awful. but it's here. It was quite cool when you add in all the gt stuff because you can use 1 template to build 20 sites using <%set whatever tags, and the little module hash things to do values. Anyway, ...
So what you do is:
1) change all the paths
2)add in a new template called whatevertemplateset__index.html
(the prefix being the template set, the suffix being the filename in the directory)
3)add a new cbuild sub specifing the two params
4)name it sdfsfddf.cgi and run it!
#!/usr/local/bin/perl
# ==================================================================
# Links SQL - enhanced directory management system
#
# Website : http://gossamer-threads.com/
# Support : http://gossamer-threads.com/scripts/support/
# CVS Info : 087,070,086,093,090
# Revision : $Id: HACKED UP nph-build.cgi,v 1.52 2001/05/17 03:00:49 alex AND A LAME SUB BY ANDY_C Exp $
#
# Copyright (c) 2001
Gossamer Threads Inc. All Rights Reserved.
# Redistribution in part or in whole strictly prohibited. Please
# see LICENSE file for full details.
# ==================================================================
# Load Time::HiRes if available for better time checking.
# Must appear here, or we get strange errors.
BEGIN { eval { require Time::HiRes; import Time::HiRes qw/time/; }; }
use lib '/path/to/admin;
#use strict;
use vars qw/$USE_HTML $TIME_START $TOTAL_TIME/;
use Links qw/$DB $IN $CFG/;
use Links::Build qw/compile/;
Links::reset_env() if ($Links::PERSIST);
$| = 1;
local $SIG{__DIE__} = \&Links::fatal;
&c_build("/path/you/want/to/build/in", "prefix for template added in template dir");
# copy that loads of times for each different property , then drop in a template with the right predix
sub c_build {
# ------------------------------------------------------------------
# Generate the added page.
#
$c_build_path = $_[0] ;
$c_set = $_[1] ;
opendir(EXTRA, "/path/to/template dir") || print "poo dearie me messed up";
@c_pages = readdir (EXTRA);
closedir (EXTRA);
if (@c_pages)
{foreach $c_pagename (@c_pages) {if ($c_pagename =~ /$c_set*/){&do;} else {}}}}
sub do{
$c_make = $c_pagename;
$c_feed = $c_pagename;
$c_make =~ s/$c_set//g;
$c_feed =~ s/\.html//g;
my $page = "$c_build_path" . "/" . "$c_make" ;
print "Made $c_pagename \n";
open (ADDED, "> $page") or _cant_open($page, $!);
print ADDED Links::SiteHTML::display("$c_feed");
close ADDED;
my $perms = oct ($CFG->{build_file_per});
chmod ($perms, $page);
}
sub _build_reset_hits {
# ------------------------------------------------------------------
# Updates the What's New flags.
#
_time_start();
print "Resetting hits and rates ... \n";
my $ret = Links::Build::build ('reset_hits', shift || {});
print "Done (", _time_display(), " s)\n\n";
return $ret;
}
sub _build_orphan_check {
# ------------------------------------------------------------------
# Check for orphan links.
#
_time_start();
print "Checking for orphan links ... \n";
my @orphans = Links::Build::build ('orphan_check', { select => ['Title', 'ID'] });
if (@orphans) {
print "\tThere are ", scalar @orphans, " links that are not in a category. Please modify or delete the following links:\n";
my $link_db = $DB->table ('Links');
foreach my $link (@orphans) {
print "\t\t$link->{ID}: $link->{Title}";
if ($USE_HTML) {
print qq~ - <a href="admin.cgi?db=Links&do=modify_search_results&ID=$link->{ID}">modify</a> | <a href="admin.cgi?db=Links&do=delete_search_results&ID=$link->{ID}">delete</a>\n~;
}
}
}
print "Done (", _time_display(), " s)\n\n";
}
sub _build_new_flags {
# ------------------------------------------------------------------
# Updates the What's New flags.
#
_time_start();
print "Updating New Flags ... \n";
my $ret = Links::Build::build ('new_flags', shift || {});
print "Done (", _time_display(), " s)\n\n";
return $ret;
}
sub _build_changed_flags {
# ------------------------------------------------------------------
# Updates the isChanged flags.
#
_time_start();
print "Updating Changed Flags ... \n";
my $ret = Links::Build::build ('changed_flags', shift || {});
print "Done (", _time_display(), " s)\n\n";
return $ret;
}
sub _build_cool_flags {
# ------------------------------------------------------------------
# Updates the What's Cool flags.
#
_time_start();
print "Updating Cool Flags ... \n";
my $ret = Links::Build::build ('cool_flags', shift || {});
print "Done (", _time_display(), " s)\n\n";
return $ret;
}
sub _reset_category_stats {
# ------------------------------------------------------------------
# Reset category stats.
#
_time_start();
print "Checking category stats ... \n";
my $db = $DB->table('Category');
my $cat_link = $DB->table('CatLinks', 'Links');
$db->indexing(0);
my $root_cat = $db->select ( ['ID', 'Full_Name', 'Number_of_Links'], { FatherID => 0 } );
while ( my ($root_id, $root_name, $nol) = $root_cat->fetchrow_array) {
my $children = $db->children ($root_id);
push @$children, $root_id;
my $str = '(' . join(',', @$children) . ')';
my $total = $cat_link->count ( GT::SQL::Condition->new (['CategoryID', 'IN', \$str], ['isValidated', '=', 'Yes']));
if ($total != $nol) {
print "\tCategory $root_name should have $total links, but is set to $nol, repairing ... ";
my $new_nol = _fix_category_stats($db, $cat_link, $root_name, $root_id, $nol);
if ($new_nol != $total) {
print "Structure Error!\n";
_check_category_struc ($db, $cat_link, $root_id, $children);
}
else {
print "$new_nol ok!\n";
}
}
}
$db->indexing(1);
print "Done (", _time_display(), " s)\n\n";
}
sub _check_category_struc {
# ------------------------------------------------------------------
# Find out where the problem is in a category with the wrong link count.
#
my ($db, $cat_link, $root_id, $children) = @_;
foreach my $child_id (@$children) {
my $cat_info = $db->get($child_id, 'HASH', ['ID', 'Full_Name', 'Number_of_Links']);
my $sub_children = $db->children ($child_id);
push @$sub_children, $child_id;
my $str = '(' . join(',', @$sub_children) . ')';
my $total = $cat_link->count ( GT::SQL::Condition->new (['CategoryID', 'IN', \$str], ['isValidated', '=', 'Yes']));
if ($total ne $cat_info->{Number_of_Links}) {
print "\t\t$cat_info->{Full_Name} reported: $cat_info->{Number_of_Links} real: $total\n";
}
}
}
sub _fix_category_stats {
# ------------------------------------------------------------------
# Fix category counts.
#
my ($db, $cat_link, $root_name, $root_id) = @_;
$db->select_options ('ORDER BY Full_Name DESC');
my $sth = $db->select ( GT::SQL::Condition->new ('Full_Name', 'LIKE', $root_name . "/%"), ['ID', 'Full_Name'] );
my %count = ();
my %seen = ();
my $count = $cat_link->count ( { CategoryID => $root_id, isValidated => 'Yes'} );
$count{$root_name} += $count;
while ( my ($id, $name) = $sth->fetchrow_array) {
$seen{$name}++ and print "Duplicate Category Name: ($id) $name\n" and next;
my $count = $cat_link->count ( { CategoryID => $id, isValidated => 'Yes' } );
$count{$name} += $count;
if ($count) {
my @uplevel = split /\//, $name;
for (0 .. $#uplevel - 1) {
my $up_name = join ('/', @uplevel[0 .. $_]);
$count{$up_name} += $count;
}
}
}
while ( my ($name, $count) = each %count) {
my $res = $db->update ( { Number_of_Links => $count }, { Full_Name => $name } );
}
return $count{$root_name};
}
sub _time_start {
# ------------------------------------------------------------------
# Start a timer.
#
$TIME_START = time;
}
sub _time_display {
# ------------------------------------------------------------------
# Return time results.
#
my $end = time;
my $elapsed = sprintf ("%.2f", $end - $TIME_START);
return $elapsed;
}
sub _header {
# ------------------------------------------------------------------
# Print intro.
#
my ($msg, $msg2, $refresh) = @_;
my $time = scalar localtime;
$refresh ||= '';
$TOTAL_TIME = time;
$refresh &&= "<meta http-equiv='Refresh' content='2; URL=$refresh'>";
if ($USE_HTML) {
print $IN->header ( -nph => $CFG->{nph_headers} );
print qq~
<html>
<head>
$refresh
<title>Building HTML Pages</title>
<body bgcolor="white">
~;
print Links::header ("Building HTML Pages: $msg", "$msg2", 0);
print qq~
<pre>Started at $time.
~;
}
else {
print "Started at $time.\n\nBuilding HTML Pages ... \n\n";
}
}
sub _footer {
# ------------------------------------------------------------------
# Print the footer.
#
my $end = time;
my $elapsed = sprintf ("%.2f", $end - $TOTAL_TIME);
print "All done. Total Time: ($elapsed s)\n";
if ($USE_HTML) {
print "</pre></body></html>\n\n";
}
}
sub _build_dir {
# ------------------------------------------------------------------
# Verifies that all neccessary directories have been created
# before we create the category file. Takes as input, the category
# to verify, and returns the full directory path.
#
my $input = shift;
my $db = $DB->table('Category');
my $clean_input = $db->as_url ($input);
my ($dir, $path) = '';
my @dirs = split /\//, $clean_input;
foreach $dir (@dirs) {
$path .= "/$dir";
$path = _valid_dir ($CFG->{build_root_path}, $path);
unless (-e "$CFG->{build_root_path}$path") {
print "\tMaking Directory ($CFG->{build_dir_per}): '$CFG->{build_root_path}$path' ...";
if (mkdir ("$CFG->{build_root_path}$path", oct ($CFG->{build_dir_per}))) {
print "Made.";
}
else { print "mkdir failed! Reason: $!."; }
print "\n";
}
}
return "$CFG->{build_root_path}$path";
}
sub _valid_dir {
# ------------------------------------------------------------------
# Only allow a-z A-Z 0-9 / - in a directory.
#
my ($root, $dir) = @_;
if (! -e $root and -d _) {
die "Root directory: $root does not exist!";
}
if ($dir !~ m,^([\w\/\-]+)$,) {
die "Invalid characters in category name: $dir. Must contain only letters, numbers, _, / and -.";
}
return $1;
}
sub _cant_open {
# ------------------------------------------------------------------
# Display a more user-friendly error then Links::fatal.
#
my ($page, $err) = @_;
my $user = eval { getpwuid($>); } || 'webserver';
if ($err =~ /permission/i) {
print "\n\n<b>ERROR:</b> Unable to open '$page' ($!)\n\n";
if (-e $page) {
print <<END_OF_DOC;
This means that the user '$user' is not able to overwrite the
existing file. Please make sure you have set the permissions
in the setup to 0666 if you plan to build from both the web
and shell at the same time.
END_OF_DOC
}
else {
print <<END_OF_DOC;
This means that the user '$user' is not able to create a file
in your pages directory. Please chmod the main directory
0777 so the program can create the file.
END_OF_DOC
}
die "Debug information";
}
else {
die "Unable to open: '$page' ($err)";
}
}