Archived
4
2

Compare commits

...

6 Commits

Author SHA1 Message Date
c4b0361104
Add MACRO show_summary
Shared macro that generates standardized summary information about
an episode.
2022-07-31 23:09:00 -04:00
f6318cd34f
Add get_avatar macro
Print hpr logo or host avatar filename.
2022-07-31 22:25:15 -04:00
858bf058ff
Add zero_pad_left macro
Pad left with four zeros.
2022-07-31 21:33:54 -04:00
536f7cce03
Add baseurl feature
Allow an optional base url to be included in generation of html files.
2022-07-31 19:25:56 -04:00
cf554571c8
Autoflush STDOUT for non verbose progress indication 2022-07-31 18:50:34 -04:00
2a61d89907
Guard against empty non existant page id key value 2022-07-31 15:14:03 -04:00
9 changed files with 100 additions and 34 deletions

View File

@ -116,7 +116,11 @@ sub main {
if (exists($config{$parsed_arg{'page'}})) {
my $page_config = $config{$parsed_arg{'page'}};
$page_config->{'page'} = $parsed_arg{'page'};
$page_config->{'root_template'} = $config{root_template}{content};
if (exists $config{root_template}{baseurl}) {
$page_config->{'baseurl'} = $config{root_template}{baseurl};
}
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);
@ -124,13 +128,12 @@ sub main {
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";
generate_page($tt, \$page_config, $preview);
}
}
else {
verbose ($verbose, "Generating page: $page_config->{'page'}");
generate_page($tt, $config{root_template}{content}, \$page_config, $preview);
generate_page($tt, \$page_config, $preview);
}
}
else {
@ -164,12 +167,12 @@ sub get_template_html (\%@) {
}
sub generate_page {
my ($tt, $root_template, $config, $preview) = @_;
my ($tt, $config, $preview) = @_;
my $html;
if (!$preview) {
$html = get_filename($$config);
}
$tt->process($root_template, $$config, $html)
$tt->process($$config->{root_template}, $$config, $html)
|| die $tt->error(), "\n";
}
@ -177,10 +180,11 @@ sub generate_page {
sub verbose {
my ($verbose, $message) = @_;
if ($verbose) {
print "$message\n";
print STDOUT "$message\n";
}
else {
print ".";
STDOUT->autoflush(1);
print STDOUT ".";
};
}
@ -238,7 +242,10 @@ sub get_filename {
}
else {
$filename = $$config{'filename'};
my $padded_index = sprintf("%04d", $$config{'id'});
my $padded_index = "";
if ($$config{'id'}) {
$padded_index = sprintf("%04d", $$config{'id'});
}
$filename =~ s/\[id\]/$padded_index/;
return $filename;
}

View File

@ -7,9 +7,12 @@ user:
password:
# Configure the root template page which pulls in the navigation and
# content templates used by each page.
# content templates used by each page. An optional baseurl property may
# be defined. This is useful when opening files directly from local
# filesystem to allow relative paths to work.
[root_template]
content: page.tpl.html
#baseurl: OPTIONAL [i.e. file://<full path to local website directory>]
# Configure the navigation menu and the content templates for each page
# of the site:

View File

@ -1,14 +1,46 @@
<!--% PROCESS 'shared-episode-summary.tpl.html' %-->
<!--% PROCESS 'shared-avatar.tpl.html' %-->
<!--% USE DBI(constants.driver, constants.user, constants.password) %-->
<!--% query_show_count = DBI.prepare('
SELECT id
FROM eps
WHERE eps.hostid = ? ')
%-->
<!--% query_shows = DBI.prepare('
SELECT
substr(\'0000\' || eps.id, -4, 4) AS [id],
CASE eps.explicit WHEN 1 THEN \'Explicit\' ELSE \'Clean\' END AS explicit ,
eps.date, eps.license, eps.duration,
eps.title, eps.summary, eps.tags,
eps.series, eps.notes,
hosts.local_image,
substr(\'0000\' || hosts.hostid, -4, 4) AS [host_id],
hosts.host, hosts.email
FROM eps INNER JOIN hosts ON eps.hostid = hosts.hostid
WHERE hosts.hostid = ?
ORDER BY date DESC ')
%-->
<!--% shows_to_count = query_show_count.execute(id); %-->
<!--% shows = query_shows.execute(id); %-->
<!--% show_count = 0 %-->
<!--% FOREACH show IN shows_to_count %-->
<!--% show_count = show_count +1; %-->
<!--% END %-->
<!--% hosts = DBI.tie('hosts', 'hostid') %-->
<article>
<!--% this_host = hosts.$id %-->
<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>
<h2><!--% this_host.host %--></h2>
<p><img src="./images/<!--% get_avatar(this_host.local_image, this_host.hostid) %-->"
height="80" alt="Host Image" /><br>
<label>Host ID</label>: <!--% this_host.hostid %--><br><br>
<label>email:</label> <u><!--% this_host.email %--></u><br>
<label>episodes:</label> <strong><!--% show_count %--></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>
<!--% FOREACH show IN shows; %-->
<!--% show_summary(show, 'hide_host') %-->
<!--% END %-->
</article>
<p><a href="contribute.html">Become a Correspondent</a></p>

View File

@ -1,7 +1,9 @@
<!--% PROCESS 'shared-utils.tpl.html' %-->
<article>
<p>
<h2 class="title">Correspondents</h2><p>For more information on how to become a Correspondent see our <a href="contribute.php">contribute</a></center> page. To add a logo here, either email one to admin at hpr or setup your email on <a href="https://en.gravatar.com/">Gravatar</a>. To protect your browsing privacy we gather the images every hour and serve them directly from HPR.<p />
<!--% USE DBI(constants.driver, constants.user, constants.password) %-->
<!--% PROCESS 'shared-avatar.tpl.html' %-->
<table>
<th >Avatar</th>
<th >Name &amp; Host ID</th>
@ -9,17 +11,17 @@
<th >Last Show</th>
<!--% FOREACH host IN DBI.query(
'select h.hostid, h.host, h.license, e.date,
CASE WHEN h.local_image = 0 THEN \'hpr_logo\' ELSE h.hostid END AS avatar
h.local_image
from hosts as h
inner join (select hostid, max(date) as date from eps group by hostid) as e
on h.hostid = e.hostid '
) %-->
<tr height="80" bgcolor="#CCCCCC">
<td><img src="./images/<!--% host.avatar%-->.png" height="80" width="80" alt="avatar" /></td>
<td><img src="./images/<!--% get_avatar(host.local_image, host.hostid) %-->" height="80" width="80" alt="avatar" /></td>
<td><strong><!--% host.host %--></strong><br />
Host ID: <a href="correspondents/<!--% host.hostid %-->.html"><!--% host.hostid %--></a></td>
Host ID: <a href="correspondents/<!--% zero_pad_left(host.hostid) %-->/index.html"><!--% host.hostid %--></a></td>
<td><!--% host.license %--></td>
<td><!--% host.date %--></td>
</tr>

View File

@ -1,3 +1,4 @@
<!--% PROCESS 'shared-avatar.tpl.html' %-->
<hr>
<article>
<header>
@ -18,8 +19,7 @@
</p>
</article>
<hr>
<!--% MACRO show_series(series) IF series != "" %--><label>Series:</label> <a href="series.php?id=11"><!--% series %--></a>.
<!--% END %-->
<!--% PROCESS 'shared-episode-summary.tpl.html' %-->
<h1>latest shows</h1>
<!--% USE DBI(constants.driver, constants.user, constants.password) %-->
<!--% FOREACH latest_episodes IN DBI.query('
@ -29,8 +29,8 @@
eps.date, eps.license, eps.duration,
eps.title, eps.summary, eps.tags,
eps.series, eps.notes,
CASE hosts.local_image WHEN 1 THEN hosts.hostid ELSE \'hpr_logo\' END AS avatar,
substr(\'0000\' || hosts.hostid, -4, 4) AS [host_id],
hosts.local_image,
hosts.hostid,
hosts.host, hosts.email
FROM eps INNER JOIN hosts ON eps.hostid = hosts.hostid
WHERE eps.date BETWEEN date(\'now\', \'-7 days\') AND date(\'now\')
@ -41,7 +41,7 @@ ORDER BY date DESC ')
<header>
<h1><a href="episodes/hpr<!--% latest_episodes.id %-->.html">hpr<!--% latest_episodes.id %--> :: <!--% latest_episodes.title %--></a></h1>
<h3><!--% latest_episodes.summary%--></h3>
<p class="meta"$><img src="./images/hosts/<!--% latest_episodes.avatar %-->.png" height="80" width="80" alt="" /></a><br>Hosted by <a href="correspondents/host<!--% latest_episodes.host_id %-->.html"><!--% latest_episodes.host %--></a> on <!--% latest_episodes.date %--> is flagged as <!--% latest_episodes.explicit %--> and released under a <!--% latest_episodes.license %--> license. <br>
<p class="meta"$><img src="./images/<!--% get_avatar(latest_episodes.local_image, latest_episodes.hostid) %-->" height="80" width="80" alt="" /></a><br>Hosted by <a href="correspondents/host<!--% latest_episodes.host_id %-->.html"><!--% latest_episodes.host %--></a> on <!--% latest_episodes.date %--> is flagged as <!--% latest_episodes.explicit %--> and released under a <!--% latest_episodes.license %--> license. <br>
<strong>Tags:</strong> <!--% latest_episodes.tags %--><em></em>.<br>
<small>listen in <a href="local/hpr<!--% latest_episodes.id %-->.ogg">ogg</a>, <a href="local/hpr<!--% latest_episodes.id %-->.spx">spx</a>, or <a href="local/hpr<!--% latest_episodes.id %-->.mp3">mp3</a> format. <!--% show_series(latest_episodes.series) %-->
<a href="eps.php?id=3628#comments">comments (0)</a></small>
@ -81,12 +81,7 @@ ORDER BY date DESC ')
ORDER BY date DESC
')
%-->
<h3 class="title"><a href="episodes/hpr<!--% last_5_weeks_episodes.id %-->.html">hpr<!--% last_5_weeks_episodes.id %--> :: <!--% last_5_weeks_episodes.title %--></a> hosted by <a href="correspondents/host<!--% last_5_weeks_episodes.id %-->.html"><!--% last_5_weeks_episodes.host %--></a>
</h3>
<p class="meta"><span><label>Released:</label> <!--% last_5_weeks_episodes.date %-->.</span> <span><label>Duration:</label> <!--% last_5_weeks_episodes.duration %-->.</span> <span><label>Flag:</label> <!--% last_5_weeks_episodes.explicit %-->.</span> <span><!--% show_series(last_5_weeks_episodes.series) %--></span> <br>
<span><label>Tags:</label> <em><!--% last_5_weeks_episodes.tags %--></em>.</span><br>
<!--% last_5_weeks_episodes.summary %-->
</p>
<!--% show_summary(last_5_weeks_episodes) %-->
<!--% END %-->
</article>
<h1>Older Shows</h1>

View File

@ -2,6 +2,9 @@
<html lang="en">
<head>
<title>Hacker Public Radio ~ The Technology Community Podcast</title>
<!--% IF baseurl %-->
<base href="<!--% baseurl %-->">
<!--% END %-->
<meta charset="utf-8" />
<meta http-equiv="X-Clacks-Overhead" content="GNU Terry Pratchett" />
<meta name="keywords" content="Technology, Tech News, Education, Training" />

View File

@ -0,0 +1,3 @@
<!--% MACRO get_avatar(has_avatar, host_id) BLOCK %-->
<!--% IF has_avatar == 0 %-->hpr_logo.png<!--% ELSE %-->hosts/<!--% host_id %-->.png<!--% END %-->
<!--% END %-->

View File

@ -0,0 +1,17 @@
<!--% MACRO show_series(series) IF series != "" %-->
<label>Series:</label> <a href="series.php?id=11"><!--% series %--></a>.
<!--% END %-->
<!--% MACRO show_summary(show, hide_host) BLOCK %-->
<h3 class="title"><a href="episodes/hpr<!--% show.id %-->.html">hpr<!--% show.id %--> :: <!--% show.title %--></a> <!--% IF hide_host == "" %-->
hosted by <a href="correspondents/host<!--% show.id %-->.html"><!--% show.host %--></a>
<!--% END %-->
</h3>
<p class="meta"><span><label>Released:</label> <!--% show.date %-->.</span> <span><label>Duration:</label> <!--% show.duration %-->.</span> <span><label>Flag:</label> <!--% show.explicit %-->.</span> <span><!--% show_series(show.series) %--></span> <br>
<span><label>Tags:</label> <em><!--% show.tags %--></em>.</span><br>
<!--% show.summary %-->
</p>
<!--% END %-->

View File

@ -0,0 +1,4 @@
<!--% MACRO zero_pad_left(word) BLOCK %-->
<!--% USE String(word) %-->
<!--% String.format("%04s") %-->
<!--% END %-->