App-Chronicle

 view release on metacpan or  search on metacpan

lib/Chronicle/Plugin/Generate/Pages.pm  view on Meta::CPAN

=cut

=head1 METHODS

Now follows documentation on the available methods.

=cut

package Chronicle::Plugin::Generate::Pages;


use strict;
use warnings;


our $VERSION = "5.1.7";


=head2 on_generate

The C<on_generate> method is automatically invoked to generate output
pages.  This particular plugin method is invoked I<after> any
C<on_initiate> methods which might be present.

This method is responsible for generating each distinct blog-post for
your site, via the theme-template C<entry.tmpl>.

If pages have previously been generated, and exist on-disk already,
then we skip regenerating them unless either:

=over 8

=item The C<--force> flag was used.

=item The post was written within the past ten days, and comments are enabled.

=back

The latter point is designed to ensure that a rebuild will pick up
any recent comments added to your posts without manual attention.

=cut

sub on_generate
{
    my ( $self, %args ) = (@_);

    my $dbh    = $args{ 'dbh' };
    my $config = $args{ 'config' };


    my $all = $dbh->prepare("SELECT id FROM blog ORDER BY date ASC") or
      die "Failed to find posts";

    my $now = time;

    my @all = ();

    $all->execute() or die "Failed to execute:" . $dbh->errstr();
    my $id;
    $all->bind_columns( undef, \$id );

    #
    # Build up the list of all the post IDs
    #
    # We could build these on-demand, but instead maintain a list
    # such that we can add next_link, next_title, etc, and allow
    # paging through blog-entries.
    #
    while ( $all->fetch() )
    {
        push( @all, $id );
    }


    #
    #  Now we have all the posts we iterate over them in-order.
    #
    for my $index ( 0 .. $#all )
    {
        my $id = $all[$index];

        #
        #  The previous blog entry and next blog entry, sequentially
        #
        my $prev_id = undef;
        my $next_id = undef;

        $prev_id = $all[$index - 1] if ( $index > 0 );
        $next_id = $all[$index + 1] if ( $index < $#all );

        #
        #  Read the details of the main entry.
        #
        my $entry = Chronicle::getBlog( dbh    => $dbh,
                                        id     => $id,
                                        config => $config
                                      );

        #
        #  The page we'll output might be down-cased.
        #
        my $page = $entry->{ 'link' }->unescaped;
        if ( $config->{ 'lower-case' } )
        {
            $page = lc($page);
            $entry->{ 'link' } = lc( $entry->{ 'link' } );
        }

        #
        #  The complete path.
        #
        my $out = $config->{ 'output' } . "/" . $page;

        #
        #  We skip posts that are already present:
        #
        #  * Unless they were posted recently and comments enabled.
        #
        # or
        #



( run in 0.820 second using v1.01-cache-2.11-cpan-2398b32b56e )