Archived
4
2

Compare commits

..

No commits in common. "75cd3e3e8521d3f996379b1080e4463f926f0956" and "4e56289338020d186e09cf63b6fb13b7b06ea9ab" have entirely different histories.

5 changed files with 23 additions and 154 deletions

View File

@ -6,14 +6,14 @@
=head1 SYNOPSIS
site-generator [OPTION]... PAGE|PAGE=<comma separated list of ids>...
site-generator [OPTION]... PAGE...
-p, --preview print generated pages to standard out
-v, --verbose use verbose mode
--help print this help message
Where I<PAGE> is a file name of a web page
or the special I<ALL> (to generate all pages).
or the special ALL (to generate all pages).
Examples:
@ -23,9 +23,6 @@
Generate the whole site:
site-generator ALL
Generate pages based on the same template:
site-generator correspondent=1,3,5..10
=head1 DESCRIPTION
This is a site generator for the Hacker Public Radio website based upon the Perl Templates Toolkit.
@ -91,12 +88,12 @@ sub main {
'verbose' => \$verbose,
) or pod2usage(1);
pod2usage(1) unless @ARGV;
my (@page_args) = @ARGV;
my (@pages) = @ARGV;
# Set flag indicating whether or not to generate all pages.
# The flag is set to true if the special argument ALL is
# passed into the generator
my $ALL = grep { $_ eq 'ALL' } @page_args;
my $ALL = grep { $_ eq 'ALL' } @pages;
# Load config file
read_config "site.cfg" => my %config;
@ -104,37 +101,22 @@ sub main {
my $tt = get_template_html($config{DBI});
if ($ALL) {
@page_args = keys %config;
@pages = keys %config;
# Remove non page sections of the configuration file
# from the generated list of pages.
@page_args= grep { $_ ne 'DBI' } @page_args;
@page_args= grep { $_ ne 'root_template' } @page_args;
@pages= grep { $_ ne 'DBI' } @pages;
@pages= grep { $_ ne 'root_template' } @pages;
};
foreach my $page_arg (@page_args) {
my %parsed_arg = parse_page_arg($page_arg);
if (exists($config{$parsed_arg{'page'}})) {
my $page_config = $config{$parsed_arg{'page'}};
$page_config->{'page'} = $parsed_arg{'page'};
foreach my $page (@pages) {
if (exists($config{$page})) {
verbose ($verbose, "Generating page: $page");
generate_page($tt, $config{root_template}{content}, \%config, $page, $preview);
if ($page_config->{'multipage'} && $page_config->{'multipage'} eq 'true') {
if (scalar @{$parsed_arg{'ids'}} == 1) {
@{$parsed_arg{'ids'}} = get_ids_from_db($tt, \$page_config);
}
foreach my $id (@{$parsed_arg{'ids'}}) {
$page_config->{'id'} = $id;
verbose ($verbose, "Generating page: $page_config->{'page'} with id: $id");
generate_page($tt, $config{root_template}{content}, \$page_config, $preview);
print "$page_config->{'page'} $page_config->{'id'}\n";
}
}
else {
verbose ($verbose, "Generating page: $page_config->{'page'}");
generate_page($tt, $config{root_template}{content}, \$page_config, $preview);
}
}
else {
verbose (1, "\nWarning: Page $parsed_arg{'page'} is not defined in the configuration file.");
verbose (1, "\nWarning: Page $page is not defined in the configuration file.");
}
}
verbose (1, "\nFinished processing the files.");
@ -164,12 +146,13 @@ sub get_template_html (\%@) {
}
sub generate_page {
my ($tt, $root_template, $config, $preview) = @_;
my ($tt, $root_template, $config, $page, $preview) = @_;
my $html;
if (!$preview) {
$html = get_filename($$config);
$html = "$page.html";
}
$tt->process($root_template, $$config, $html)
$tt->process($root_template, $config->{$page}, $html)
|| die $tt->error(), "\n";
}
@ -183,73 +166,3 @@ sub verbose {
print ".";
};
}
sub parse_page_arg {
my ($page_arg) = @_;
# Split page name from page ids if available.
my ($page, $ids) = split(/=/, $page_arg);
my @ids = [];
if(!$ids) {
$ids = "";
}
else {
# Parse the page ids and push them onto @ids array
my @ids_by_comma = split(/\,/, $ids);
foreach my $id_by_comma (@ids_by_comma) {
my @ids_for_range = split(/\.\./, $id_by_comma);
if ((scalar @ids_for_range) == 2) {
push @ids, $ids_for_range[0]..$ids_for_range[1];
}
elsif ((scalar @ids_for_range) == 1) {
push @ids, $ids_for_range[0];
}
else {
verbose (1, "\nWarning: Page $page id range $id_by_comma could not be parsed.");
}
}
}
return ('page' => $page, 'ids' => [@ids]);
}
sub get_ids_from_db {
# Use a template to generate a string of page identifiers.
# The template should return the string in the form of
# <comma><identifier><comma><identifier>...
#
my ($tt, $config) = @_;
my $selected_ids = "";
my $id_template = "ids-$$config->{'page'}.tpl.html";
$tt->process($id_template, $$config, \$selected_ids)
|| die $tt->error(), "\n";
return split(/,/, substr($selected_ids, 1));
}
sub get_filename {
my ($config) = @_;
my $filename = "output.html";
my $base_path = "";
if ($$config{'filename'}) {
if (substr($$config{'filename'}, -1) eq '/') {
$base_path = $$config{'filename'};
}
else {
$filename = $$config{'filename'};
my $padded_index = sprintf("%04d", $$config{'id'});
$filename =~ s/\[id\]/$padded_index/;
return $filename;
}
}
# Default naming if full filename configuration is not supplied.
if ($$config{'multipage'} && $$config{'multipage'} eq 'true') {
my $padded_index = sprintf("%04d", $$config{'id'});
$filename = "$base_path$$config{'page'}${padded_index}.html";
}
else {
$filename = "$base_path$$config{'page'}.html";
}
return $filename;
}

View File

@ -13,20 +13,9 @@ content: page.tpl.html
# Configure the navigation menu and the content templates for each page
# of the site:
# Configure filename if default name is not desired
# (Default is "ROOT/[page_name].html"):
#
# filename: OPTIONAL <relative path from ROOT -- optional>
# * <directory path> -- Must end in forward slash. File will be created
# in this path with the default naming scheme.
# * <file name> -- May include a relative path. Should include the file
# extension. May have [id] marker in path or name which
# will be substituted with a padded page id.
# Configure pages which use the same content template:
#
# multipage: OPTIONAL true | false (DEFAULT = false)
# [page_name]
# navigation: <name of navigation template>
# content: <name of page content template>
[index]
navigation: navigation-main.tpl.html
@ -39,14 +28,9 @@ content: content-about.tpl.html
[correspondents]
navigation: navigation-about.tpl.html
content: content-correspondents.tpl.html
filename: correspondents/index.html
[contact]
navigation: navigation-about.tpl.html
content: content-contact.tpl.html
[correspondent]
navigation: navigation-about.tpl.html
content: content-correspondent.tpl.html
multipage: true
filename: correspondents/[id]/index.html

View File

@ -1,14 +0,0 @@
<article>
<h2 class="title">Correspondent</h2>
<h2>Rho`n</h2>
<p><img src="./images/hosts/293.png" height="80" alt="Host Image" /><br>
<label>Host ID</label>:<!--% id %--><br><br>
<label>email:</label> <u>roan.horning.nospam@nospam.gmail.com</u><br>
<label>episodes:</label> <strong>12</strong>
</p>
<h3><a href="eps.php?id=3647">hpr3647 :: Weekend projects</a></h3>
<p class="meta"><strong>Released:</strong> 2022-07-26. <strong>Duration:</strong> 00:16:44. <strong>Flag:</strong> Clean. <strong>Series:</strong> <a href="series.php?id=0">general</a>. <br>
<strong>Tags:</strong> <em>diy, repairs, umbrella, basketball</em>.<br>
Rho`n rambles about some weekend projects</p>
<p><a href="contribute.php">Become a Correspondent</a></p>
</article>

View File

@ -1,7 +0,0 @@
<!--% USE DBI(constants.driver, constants.user, constants.password) %-->
<!--% FOREACH host IN DBI.query(
'select h.hostid from hosts as h'
) %-->
,<!--% host.hostid %-->
<!--% END %-->

View File

@ -1,9 +1,3 @@
<!--% IF config.multipage == "true" && config.ids.count() > 0 %-->
<!--% ELSIF config.multipage == "true" %-->
<!--% ELSE %-->
<!--% page_ids = ['0'] %-->
<!--% END %-->
<!--% FOREACH page_id IN page_ids %-->
<!DOCTYPE HTML>
<html lang="en">
<head>
@ -27,7 +21,7 @@
<link rel="alternate" type="application/rss+xml" title="Hacker Public Radio MP3 RSS" href="/hpr_mp3_rss.php" />
<link rel="alternate" type="application/rss+xml" title="Hacker Public Radio Comments RSS" href="/comments_rss.php" />
<link rel="license" title="cc by 3.0" href="https://creativecommons.org/licenses/by-sa/3.0/" />
<link href="./css/hpr.css" rel="stylesheet" />
<link href="/css/hpr.css" rel="stylesheet" />
<!--[if IE]>
<link rel="stylesheet" href="css/hpr.css" media="screen" type="text/css" />
<script src="/JavaScript/html5.js"></script>
@ -130,4 +124,3 @@
</footer>
</div>
<!-- shadow -->
<!--% END %-->