Compare commits
No commits in common. "75cd3e3e8521d3f996379b1080e4463f926f0956" and "4e56289338020d186e09cf63b6fb13b7b06ea9ab" have entirely different histories.
75cd3e3e85
...
4e56289338
121
site-generator
121
site-generator
@ -6,14 +6,14 @@
|
|||||||
|
|
||||||
=head1 SYNOPSIS
|
=head1 SYNOPSIS
|
||||||
|
|
||||||
site-generator [OPTION]... PAGE|PAGE=<comma separated list of ids>...
|
site-generator [OPTION]... PAGE...
|
||||||
|
|
||||||
-p, --preview print generated pages to standard out
|
-p, --preview print generated pages to standard out
|
||||||
-v, --verbose use verbose mode
|
-v, --verbose use verbose mode
|
||||||
--help print this help message
|
--help print this help message
|
||||||
|
|
||||||
Where I<PAGE> is a file name of a web page
|
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:
|
Examples:
|
||||||
|
|
||||||
@ -23,9 +23,6 @@
|
|||||||
Generate the whole site:
|
Generate the whole site:
|
||||||
site-generator ALL
|
site-generator ALL
|
||||||
|
|
||||||
Generate pages based on the same template:
|
|
||||||
site-generator correspondent=1,3,5..10
|
|
||||||
|
|
||||||
=head1 DESCRIPTION
|
=head1 DESCRIPTION
|
||||||
|
|
||||||
This is a site generator for the Hacker Public Radio website based upon the Perl Templates Toolkit.
|
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,
|
'verbose' => \$verbose,
|
||||||
) or pod2usage(1);
|
) or pod2usage(1);
|
||||||
pod2usage(1) unless @ARGV;
|
pod2usage(1) unless @ARGV;
|
||||||
my (@page_args) = @ARGV;
|
my (@pages) = @ARGV;
|
||||||
|
|
||||||
# Set flag indicating whether or not to generate all pages.
|
# Set flag indicating whether or not to generate all pages.
|
||||||
# The flag is set to true if the special argument ALL is
|
# The flag is set to true if the special argument ALL is
|
||||||
# passed into the generator
|
# passed into the generator
|
||||||
my $ALL = grep { $_ eq 'ALL' } @page_args;
|
my $ALL = grep { $_ eq 'ALL' } @pages;
|
||||||
|
|
||||||
# Load config file
|
# Load config file
|
||||||
read_config "site.cfg" => my %config;
|
read_config "site.cfg" => my %config;
|
||||||
@ -104,37 +101,22 @@ sub main {
|
|||||||
my $tt = get_template_html($config{DBI});
|
my $tt = get_template_html($config{DBI});
|
||||||
|
|
||||||
if ($ALL) {
|
if ($ALL) {
|
||||||
@page_args = keys %config;
|
@pages = keys %config;
|
||||||
|
|
||||||
# Remove non page sections of the configuration file
|
# Remove non page sections of the configuration file
|
||||||
# from the generated list of pages.
|
# from the generated list of pages.
|
||||||
@page_args= grep { $_ ne 'DBI' } @page_args;
|
@pages= grep { $_ ne 'DBI' } @pages;
|
||||||
@page_args= grep { $_ ne 'root_template' } @page_args;
|
@pages= grep { $_ ne 'root_template' } @pages;
|
||||||
};
|
};
|
||||||
foreach my $page_arg (@page_args) {
|
foreach my $page (@pages) {
|
||||||
my %parsed_arg = parse_page_arg($page_arg);
|
|
||||||
if (exists($config{$parsed_arg{'page'}})) {
|
if (exists($config{$page})) {
|
||||||
my $page_config = $config{$parsed_arg{'page'}};
|
verbose ($verbose, "Generating page: $page");
|
||||||
$page_config->{'page'} = $parsed_arg{'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 {
|
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.");
|
verbose (1, "\nFinished processing the files.");
|
||||||
@ -164,12 +146,13 @@ sub get_template_html (\%@) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub generate_page {
|
sub generate_page {
|
||||||
my ($tt, $root_template, $config, $preview) = @_;
|
my ($tt, $root_template, $config, $page, $preview) = @_;
|
||||||
|
|
||||||
my $html;
|
my $html;
|
||||||
if (!$preview) {
|
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";
|
|| die $tt->error(), "\n";
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -183,73 +166,3 @@ sub verbose {
|
|||||||
print ".";
|
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;
|
|
||||||
}
|
|
||||||
|
24
site.cfg
24
site.cfg
@ -13,20 +13,9 @@ content: page.tpl.html
|
|||||||
|
|
||||||
# Configure the navigation menu and the content templates for each page
|
# Configure the navigation menu and the content templates for each page
|
||||||
# of the site:
|
# of the site:
|
||||||
|
# [page_name]
|
||||||
# Configure filename if default name is not desired
|
# navigation: <name of navigation template>
|
||||||
# (Default is "ROOT/[page_name].html"):
|
# content: <name of page content template>
|
||||||
#
|
|
||||||
# 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)
|
|
||||||
|
|
||||||
[index]
|
[index]
|
||||||
navigation: navigation-main.tpl.html
|
navigation: navigation-main.tpl.html
|
||||||
@ -39,14 +28,9 @@ content: content-about.tpl.html
|
|||||||
[correspondents]
|
[correspondents]
|
||||||
navigation: navigation-about.tpl.html
|
navigation: navigation-about.tpl.html
|
||||||
content: content-correspondents.tpl.html
|
content: content-correspondents.tpl.html
|
||||||
filename: correspondents/index.html
|
|
||||||
|
|
||||||
[contact]
|
[contact]
|
||||||
navigation: navigation-about.tpl.html
|
navigation: navigation-about.tpl.html
|
||||||
content: content-contact.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
|
|
||||||
|
@ -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>
|
|
@ -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 %-->
|
|
||||||
|
|
@ -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>
|
<!DOCTYPE HTML>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<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 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="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 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]>
|
<!--[if IE]>
|
||||||
<link rel="stylesheet" href="css/hpr.css" media="screen" type="text/css" />
|
<link rel="stylesheet" href="css/hpr.css" media="screen" type="text/css" />
|
||||||
<script src="/JavaScript/html5.js"></script>
|
<script src="/JavaScript/html5.js"></script>
|
||||||
@ -130,4 +124,3 @@
|
|||||||
</footer>
|
</footer>
|
||||||
</div>
|
</div>
|
||||||
<!-- shadow -->
|
<!-- shadow -->
|
||||||
<!--% END %-->
|
|
||||||
|
Reference in New Issue
Block a user