Skip to content

Commit

Permalink
fix slide dumper
Browse files Browse the repository at this point in the history
fix the write of html (was omitted when I prevented scripts having lame contents);
add header bar for next|index links;
tell what made the dump
  • Loading branch information
mcast committed Mar 11, 2013
1 parent 929925d commit b12fd79
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions techtalk-pse.pl
Expand Up @@ -183,6 +183,7 @@ =head2 OPTIONS
my ($progdir, $PACKAGE) = $0 =~ m{^(.*)/([^/.]+)(?:\.\w+)?$}
or die "Cannot find self with both hands";
my ($VERSION) = qx{ cd $progdir; git describe --tags --dirty };
chomp $VERSION;

pod2usage (1) if $help;
if ($version) {
Expand Down Expand Up @@ -470,23 +471,35 @@ sub do_dump {
my @index;
my $dumpdir = "$talkdir/dump";
-d $dumpdir or mkdir $dumpdir or die "mkdir $dumpdir: $!";
foreach my $slide (@files) {
my $last_html;
foreach my $slide (reverse @files) {
my $name = $slide->{name};
my $outfn = $name;
$outfn =~ s{\.[^.]+$}{.html};
push @index, $outfn;
unshift @index, $outfn;
my $html;
if ($slide->{ext} eq 'html') {
$html = slurp("$talkdir/$name");
} elsif ($slide->{ext} eq 'md') {
$html = md2html($name, 1);
} else {
my $txt = "Slide <tt> $name </tt> doesn't render nicely to HTML.";
$index[-1] = \$txt;
$index[0] = \$txt;
next;
}
my @hdr;
push @hdr, qq{<a href="$last_html"> Next </a>} if defined $last_html; # no going back
push @hdr, qq{<a href="index.html"> Index </a>};
@hdr = ('<div class=dump_header>', (join ' | ', @hdr), "</div>\n");
$html =~ s{(<body>)}{$1 @hdr}i; # no dump_header without proper HTML
write_file("$dumpdir/$outfn", { atomic => 1 }, $html);
$last_html = $outfn;
}
my $html = join "\n", '<html><head><title>Slides index</title><body><ol>',
(map { ref $_ ? qq{<li> $$_ </li>} : qq{<li><a href="$_"> $_ </a> </li>}} @index), "</ol></body></html>\n";
my $html = join "\n", "<html><head><title>Slides index</title><body class=dump_index>
<h1> Slides dump index </h1>
<p class=vsn> These pages were dumped from a <tt>techtalk-pse</tt> presentation by $VERSION. </p>
<ol>",
(map { ref $_ ? qq{<li> $$_ </li>} : qq{<li><a href="$_"> $_ </a> </li>}} @index), "</ol></body></html>\n";
write_file("$dumpdir/index.html", { atomic => 1 }, $html);
}

Expand Down

0 comments on commit b12fd79

Please sign in to comment.