App-Chronicle
view release on metacpan or search on metacpan
lib/Chronicle/Plugin/Generate/LowerCase.pm view on Meta::CPAN
my $tmpl = do {local $/; <DATA>};
#
# If there is no template read then something weird has happened
#
return unless ( $tmpl && length($tmpl) );
#
# Load the template
#
$c = Chronicle::load_template( undef, $tmpl );
}
#
# At this point we should have one of the two templates loaded,
# but if not .. we'll just return.
#
return unless ($c);
#
# Now we have all the posts we iterate over them in-order.
#
for my $index ( 0 .. $#all )
{
#
# The ID of the entry we're processing.
#
my $id = $all[$index];
#
# Read the details of the main entry.
#
my $entry = Chronicle::getBlog( dbh => $dbh,
id => $id,
config => $config
);
#
# Does the entry have a mixed-case title?
#
if ( $entry->{ 'link' } =~ /[A-Z]/ )
{
#
# Ensure we have a full output path - because a plugin might have given us a dated-path.
#
my $dir = File::Basename::dirname(
$config->{ 'output' } . "/" . $entry->{ 'link' } );
if ( !-d $dir )
{
File::Path::make_path( $dir,
{ verbose => 0,
mode => oct("755"),
} );
}
my $out =
$config->{ 'output' } . "/" . $entry->{ 'link' }->unescaped;
$config->{ 'verbose' } &&
print "Writing redirection to $out for mixed-case post " .
lc( $entry->{ 'link' } ) . "\n";
#
# Clear the template, and populate it
#
$c->param( top => $config->{ 'top' } );
$c->param( target => lc( $entry->{ 'link' } ) );
#
# Write it out
#
open( my $handle, ">:encoding(UTF-8)", $out ) or
die "Failed to open `$out' for writing: $!";
print $handle $c->output();
close($handle);
}
}
$all->finish();
}
1;
=head1 LICENSE
This module is free software; you can redistribute it and/or modify it
under the terms of either:
a) the GNU General Public License as published by the Free Software
Foundation; either version 2, or (at your option) any later version,
or
b) the Perl "Artistic License".
=cut
=head1 AUTHOR
Steve Kemp <steve@steve.org.uk>
=cut
__DATA__
<!DOCTYPE html>
<html lang="en">
<head>
<title>Blog Post Moved</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="refresh" content="0; url=<!-- tmpl_var name='top' --><!-- tmpl_var name='target' -->">
<link rel="canonical" href="<!-- tmpl_var name='top' --><!-- tmpl_var name='target' -->">
</head>
<body>
( run in 0.766 second using v1.01-cache-2.11-cpan-39bf76dae61 )