| 1 | # ABSTRACT: Generator for category pages | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | |||||||||||||||||||||
| 4 | package HiD::Generator::CategoryPages; | ||||||||||||||||||||
| 5 | 1 | our $AUTHORITY = 'cpan:GENEHACK'; | |||||||||||||||||||
| 6 | 1 | $HiD::Generator::CategoryPages::VERSION = '1.96'; | |||||||||||||||||||
| 7 | 1 | ▶ | use Moose; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 1 | with 'HiD::Generator'; | |||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 1 | ▶ | use 5.014; # strict, unicode_strings | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 1 | ▶ | use HiD::Page; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 1 | has 'destination' => ( | |||||||||||||||||||
| 15 | is => 'ro' , | ||||||||||||||||||||
| 16 | isa => 'HiD_DirPath' , | ||||||||||||||||||||
| 17 | ); | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | sub generate { | ||||||||||||||||||||
| 21 | 0 | ▶ | my( $self , $site ) = @_; | ||||||||||||||||||
|
Subroutine
generate: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | 0 | ▶ | return unless $site->config->{categories}{generate}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | my $input_file = $site->config->{categories}{layout} | ||||||||||||||||||||
| 26 | 0 | ▶ | or die "Must define categories.layout in config if categories.generate is enabled"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 0 | ▶ | my $destination = $self->destination // $site->destination; | ||||||||||||||||||
|
Condition0%0/3
$self->destination // $site->destination
MC/DC0%0/2
$self->destination // $site->destination
$self->destination
$site->destination
Truth table0%0/3
A // B
A= $self->destinationB= $site->destination
| |||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | 0 | $self->_create_destination_directory_if_needed( $destination ); | |||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 0 | foreach my $category ( keys %{ $site->categories } ) { | |||||||||||||||||||
| 33 | 0 | my $page = HiD::Page->new({ | |||||||||||||||||||
| 34 | dest_dir => $destination , | ||||||||||||||||||||
| 35 | hid => $site , | ||||||||||||||||||||
| 36 | url => "category/$category/" , | ||||||||||||||||||||
| 37 | input_filename => $input_file , | ||||||||||||||||||||
| 38 | layouts => $site->layouts , | ||||||||||||||||||||
| 39 | }); | ||||||||||||||||||||
| 40 | 0 | $page->metadata->{category} = $category; | |||||||||||||||||||
| 41 | 0 | $page->metadata->{posts} = $site->categories->{$category}; | |||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | 0 | $site->add_input( "Category_$category" => 'page' ); | |||||||||||||||||||
| 44 | 0 | $site->add_object( $page ); | |||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | 0 | $site->INFO( "* Injected tag page for '$category'"); | |||||||||||||||||||
| 47 | } | ||||||||||||||||||||
| 48 | } | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||
| 51 | 1 | 1; | |||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | __END__ | ||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | =pod | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | =encoding UTF-8 | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | =head1 NAME | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | HiD::Generator::CategoryPages - Generator for category pages | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | =head1 DESCRIPTION | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | This is an example of a generator plugin. It generates one page per key in the | ||||||||||||||||||||
| 66 | C<< $site->categories >> hash, and injects that page into the site so that it will | ||||||||||||||||||||
| 67 | be published. | ||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | This plugin can be used with minimal work on your part by enabling the | ||||||||||||||||||||
| 70 | required options in your configuration and putting a file like the following | ||||||||||||||||||||
| 71 | example into the C<_plugins> directory of your site: | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | package Categories; | ||||||||||||||||||||
| 74 | use Moose; | ||||||||||||||||||||
| 75 | extends 'HiD::Generator::CategoryPages'; | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | # you override the default destination like so | ||||||||||||||||||||
| 78 | has '+destination' => ( default => '_site/subdir' ); | ||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | __PACKAGE__->meta->make_immutable; | ||||||||||||||||||||
| 81 | 1; | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | As shown above, you can control where the resulting pages are generated by | ||||||||||||||||||||
| 84 | overridding the C<destination> attribute. If you want to tweak more than that, | ||||||||||||||||||||
| 85 | you're probably better off just copying the whole module into your C<_plugins> | ||||||||||||||||||||
| 86 | directory and modifying it directly. | ||||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | =head1 METHODS | ||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | =head2 generate | ||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | =head1 VERSION | ||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | version 1.96 | ||||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | =head1 AUTHOR | ||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | John SJ Anderson <genehack@genehack.org> | ||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | This software is copyright (c) 2015 by John SJ Anderson. | ||||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||
| 105 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | =cut | ||||||||||||||||||||