forked from rho_n/hpr_generator
Allow multiple pages to be generated from one template
Feature to allow generation of host and episode pages.
This commit is contained in:
parent
873cfda86a
commit
75cd3e3e85
@ -6,14 +6,14 @@
|
|||||||
|
|
||||||
=head1 SYNOPSIS
|
=head1 SYNOPSIS
|
||||||
|
|
||||||
site-generator [OPTION]... PAGE...
|
site-generator [OPTION]... PAGE|PAGE=<comma separated list of ids>...
|
||||||
|
|
||||||
-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 ALL (to generate all pages).
|
or the special I<ALL> (to generate all pages).
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
|
|
||||||
@ -23,6 +23,9 @@
|
|||||||
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.
|
||||||
@ -105,20 +108,24 @@ sub main {
|
|||||||
|
|
||||||
# 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' } @pages_args;
|
@page_args= grep { $_ ne 'DBI' } @page_args;
|
||||||
@page_args= grep { $_ ne 'root_template' } @page_args;
|
@page_args= grep { $_ ne 'root_template' } @page_args;
|
||||||
};
|
};
|
||||||
foreach my $page_arg (@page_args) {
|
foreach my $page_arg (@page_args) {
|
||||||
my %page_arg = parse_page_arg($page_arg);
|
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'};
|
||||||
|
|
||||||
if (exists($config{$page_arg{'page'}})) {
|
if ($page_config->{'multipage'} && $page_config->{'multipage'} eq 'true') {
|
||||||
my $page_config = $config{$page_arg{'page'}};
|
if (scalar @{$parsed_arg{'ids'}} == 1) {
|
||||||
$page_config->{'page'} = $page_arg{'page'};
|
@{$parsed_arg{'ids'}} = get_ids_from_db($tt, \$page_config);
|
||||||
|
}
|
||||||
if ($page_config->{'multipage'}) {
|
foreach my $id (@{$parsed_arg{'ids'}}) {
|
||||||
print "multipage\n";
|
|
||||||
foreach my $id ($page_config->{'ids'}) {
|
|
||||||
$page_config->{'id'} = $id;
|
$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 {
|
else {
|
||||||
@ -127,7 +134,7 @@ sub main {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
verbose (1, "\nWarning: Page $page_arg{'page'} is not defined in the configuration file.");
|
verbose (1, "\nWarning: Page $parsed_arg{'page'} is not defined in the configuration file.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
verbose (1, "\nFinished processing the files.");
|
verbose (1, "\nFinished processing the files.");
|
||||||
@ -158,7 +165,6 @@ sub get_template_html (\%@) {
|
|||||||
|
|
||||||
sub generate_page {
|
sub generate_page {
|
||||||
my ($tt, $root_template, $config, $preview) = @_;
|
my ($tt, $root_template, $config, $preview) = @_;
|
||||||
print Dumper($$config);
|
|
||||||
my $html;
|
my $html;
|
||||||
if (!$preview) {
|
if (!$preview) {
|
||||||
$html = get_filename($$config);
|
$html = get_filename($$config);
|
||||||
@ -203,7 +209,22 @@ sub parse_page_arg {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ('page', $page, 'ids', @ids);
|
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 {
|
sub get_filename {
|
||||||
|
9
site.cfg
9
site.cfg
@ -24,6 +24,9 @@ content: page.tpl.html
|
|||||||
# extension. May have [id] marker in path or name which
|
# extension. May have [id] marker in path or name which
|
||||||
# will be substituted with a padded page id.
|
# 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
|
||||||
@ -42,4 +45,8 @@ filename: correspondents/index.html
|
|||||||
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
|
||||||
|
14
templates/content-correspondent.tpl.html
Normal file
14
templates/content-correspondent.tpl.html
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<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>
|
7
templates/ids-correspondent.tpl.html
Normal file
7
templates/ids-correspondent.tpl.html
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<!--% USE DBI(constants.driver, constants.user, constants.password) %-->
|
||||||
|
<!--% FOREACH host IN DBI.query(
|
||||||
|
'select h.hostid from hosts as h'
|
||||||
|
) %-->
|
||||||
|
,<!--% host.hostid %-->
|
||||||
|
<!--% END %-->
|
||||||
|
|
@ -1,3 +1,9 @@
|
|||||||
|
<!--% 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>
|
||||||
@ -21,7 +27,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>
|
||||||
@ -124,3 +130,4 @@
|
|||||||
</footer>
|
</footer>
|
||||||
</div>
|
</div>
|
||||||
<!-- shadow -->
|
<!-- shadow -->
|
||||||
|
<!--% END %-->
|
||||||
|
Loading…
Reference in New Issue
Block a user