| 1 | package App::Dapper::Collections; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | =head1 NAME | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | App::Dapper::Collections - Category pages, tag pages and pagination. | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | After the source files are read, Dapper can generate a page for each | ||||||||||||||||||||||||||||
| 10 | category and each tag, and split long lists of pages across several pages. | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | Category and tag pages are turned on in C<_config.yml>, and are rendered with | ||||||||||||||||||||||||||||
| 13 | the layout you name: | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | category_pages: | ||||||||||||||||||||||||||||
| 16 | layout: category # _layout/category.html | ||||||||||||||||||||||||||||
| 17 | urlpattern: /:category/ # the default | ||||||||||||||||||||||||||||
| 18 | per_page: 10 # optional: split into pages of 10 | ||||||||||||||||||||||||||||
| 19 | tag_pages: | ||||||||||||||||||||||||||||
| 20 | layout: tag | ||||||||||||||||||||||||||||
| 21 | urlpattern: /tags/:tag/ # the default | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | Each generated page has C<page.title> (the category or tag), C<page.category> | ||||||||||||||||||||||||||||
| 24 | or C<page.tag>, and C<page.posts> (its pages, newest first). With C<per_page>, | ||||||||||||||||||||||||||||
| 25 | C<page.posts> holds just the pages for that page, and C<paginator> describes | ||||||||||||||||||||||||||||
| 26 | the whole set. The URL of each one is in C<site.category_pages> and | ||||||||||||||||||||||||||||
| 27 | C<site.tag_pages>, so layouts can link to them: | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | <a href="[% site.tag_pages.$tag %]">[% tag %]</a> | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | Any page can list pages across several pages with C<paginate> in its front | ||||||||||||||||||||||||||||
| 32 | matter: | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | paginate: | ||||||||||||||||||||||||||||
| 35 | category: blog # or tag: perl; leave both out for every post | ||||||||||||||||||||||||||||
| 36 | per_page: 10 | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | In its layout (or its content, with C<template: true>), C<paginator.items> | ||||||||||||||||||||||||||||
| 39 | holds that page's share of the posts, newest first. | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | =head2 The paginator | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | paginator.items the pages to show on this page | ||||||||||||||||||||||||||||
| 44 | paginator.page this page's number, starting at 1 | ||||||||||||||||||||||||||||
| 45 | paginator.per_page pages per page | ||||||||||||||||||||||||||||
| 46 | paginator.total_pages how many pages there are | ||||||||||||||||||||||||||||
| 47 | paginator.total_items how many items there are | ||||||||||||||||||||||||||||
| 48 | paginator.previous_url the URL of the previous page (if there is one) | ||||||||||||||||||||||||||||
| 49 | paginator.next_url the URL of the next page (if there is one) | ||||||||||||||||||||||||||||
| 50 | paginator.first_url, paginator.last_url | ||||||||||||||||||||||||||||
| 51 | paginator.pages a list of { number, url } for every page | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | Page 1 keeps the page's own URL; page 2 is at C<page/2/> below it. | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | =cut | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 32 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 58 | 32 | ▶ | use 5.010; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 59 | 32 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 60 | 32 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 32 | ▶ | use File::Spec::Functions qw/ canonpath catfile /; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 32 | ▶ | use App::Dapper::Utils; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | =head2 generate | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | Takes the Dapper object, adds category and tag pages to the site if they are | ||||||||||||||||||||||||||||
| 69 | turned on, and expands every paginated page into its set of pages. | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | =cut | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 0 | ▶ | sub generate { | ||||||||||||||||||||||||||
|
Subroutine
generate: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 74 | 0 | my ($dapper) = @_; | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 0 | my $site = $dapper->{site}; | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | # The settings from _config.yml; the same names then hold the URL of each | ||||||||||||||||||||||||||||
| 79 | # generated page | ||||||||||||||||||||||||||||
| 80 | 0 | my %settings = (category => $site->{category_pages}, tag => $site->{tag_pages}); | |||||||||||||||||||||||||||
| 81 | 0 | $site->{category_pages} = {}; | |||||||||||||||||||||||||||
| 82 | 0 | $site->{tag_pages} = {}; | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 0 | my @generated; | |||||||||||||||||||||||||||
| 85 | 0 | for my $kind (qw/ category tag /) { | |||||||||||||||||||||||||||
| 86 | 0 | my $value = $settings{$kind}; | |||||||||||||||||||||||||||
| 87 | 0 | ▶ | next unless defined $value; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 0 | ▶ | die "error: ${kind}_pages in $dapper->{config} must be settings such as layout: $kind\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | unless ref $value eq 'HASH'; | ||||||||||||||||||||||||||||
| 90 | 0 | ▶ | my $lists = $kind eq 'tag' ? $site->{tags} : $site->{categories}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | 0 | push @generated, list_pages($dapper, $kind, $lists, $site->{"${kind}_pages"}, $value); | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 0 | my @pages; | |||||||||||||||||||||||||||
| 95 | 0 | for my $page (@{$site->{pages}}, @generated) { | |||||||||||||||||||||||||||
| 96 | 0 | push @pages, paginate($dapper, $page); | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | 0 | $site->{pages} = \@pages; | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | =head2 list_pages | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | Takes the Dapper object, the kind of list (C<category> or C<tag>), the hash of | ||||||||||||||||||||||||||||
| 104 | names to pages, the hash to record each list page's URL in, and the settings | ||||||||||||||||||||||||||||
| 105 | from C<_config.yml>. Returns the generated pages. | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | =cut | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 0 | ▶ | sub list_pages { | ||||||||||||||||||||||||||
|
Subroutine
list_pages: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||
| 110 | 0 | my ($dapper, $kind, $lists, $urls, $settings) = @_; | |||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 0 | my $site = $dapper->{site}; | |||||||||||||||||||||||||||
| 113 | 0 | my $label = "${kind}_pages"; | |||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | die "error: $label in $dapper->{config} needs a layout, e.g. layout: $kind\n" | ||||||||||||||||||||||||||||
| 116 | 0 | ▶ | unless defined $settings->{layout} and length $settings->{layout}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $settings->{"layout"} and length $settings->{"layout"}
MC/DC0%0/2
defined $settings->{"layout"} and length $settings->{"layout"}
defined $settings->{"layout"}
length $settings->{"layout"}
Truth table0%0/3
A and B
A= defined $settings->{"layout"}B= length $settings->{"layout"}
| |||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | my $pattern = defined $settings->{urlpattern} ? $settings->{urlpattern} | ||||||||||||||||||||||||||||
| 119 | 0 | ▶ | : $kind eq 'tag' ? '/tags/:tag/' | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 120 | : '/:category/'; | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 0 | my @pages; | |||||||||||||||||||||||||||
| 123 | 0 | for my $name (sort keys %$lists) { | |||||||||||||||||||||||||||
| 124 | 0 | my @posts = reverse @{$lists->{$name}}; | |||||||||||||||||||||||||||
| 125 | 0 | ▶ | my $value = $kind eq 'tag' ? App::Dapper::Utils::slugify($name) : $name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | my %page = ( | ||||||||||||||||||||||||||||
| 128 | title => $name, | ||||||||||||||||||||||||||||
| 129 | $kind => $name, | ||||||||||||||||||||||||||||
| 130 | posts => \@posts, | ||||||||||||||||||||||||||||
| 131 | layout => $settings->{layout}, | ||||||||||||||||||||||||||||
| 132 | extension => $site->{extension}, | ||||||||||||||||||||||||||||
| 133 | date => $posts[0]->{date}, | ||||||||||||||||||||||||||||
| 134 | content => '', | ||||||||||||||||||||||||||||
| 135 | source => "$label ($name)", | ||||||||||||||||||||||||||||
| 136 | generated => 1, | ||||||||||||||||||||||||||||
| 137 | sitemap => $settings->{sitemap}, | ||||||||||||||||||||||||||||
| 138 | 0 | ); | |||||||||||||||||||||||||||
| 139 | 0 | $page{url} = App::Dapper::expand_urlpattern($pattern, { $kind => $value }); | |||||||||||||||||||||||||||
| 140 | 0 | set_filename($dapper, \%page); | |||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 0 | ▶ | if ($settings->{per_page}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 143 | 0 | $page{paginate} = { items => \@posts, per_page => $settings->{per_page} }; | |||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 0 | $urls->{$name} = $page{url}; | |||||||||||||||||||||||||||
| 147 | 0 | push @pages, \%page; | |||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 0 | return @pages; | |||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | =head2 paginate | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | Takes the Dapper object and a page. If the page has C<paginate> settings, | ||||||||||||||||||||||||||||
| 156 | returns the page followed by its further pages, each with a C<paginator>; | ||||||||||||||||||||||||||||
| 157 | otherwise returns the page unchanged. | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | =cut | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 0 | ▶ | sub paginate { | ||||||||||||||||||||||||||
|
Subroutine
paginate: not called CC=18 SCAR=58.3
Pod
documented
| |||||||||||||||||||||||||||||
| 162 | 0 | my ($dapper, $page) = @_; | |||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | 0 | my $settings = $page->{paginate}; | |||||||||||||||||||||||||||
| 165 | 0 | ▶ | return $page unless $settings; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | 0 | ▶ | $settings = { per_page => $settings } unless ref $settings; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 168 | 0 | ▶ | die "error: paginate in $page->{source} must be a number or settings such as per_page: 10\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 169 | unless ref $settings eq 'HASH'; | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | 0 | ▶ | my $per_page = $settings->{per_page} || 10; | ||||||||||||||||||||||||||
|
Condition0%0/2
$settings->{'per_page'} || 10
MC/DC0%0/1
$settings->{'per_page'} || 10
$settings->{'per_page'}
Truth table0%0/2
A
A= $settings->{'per_page'}
| |||||||||||||||||||||||||||||
| 172 | 0 | ▶ | die "error: per_page in $page->{source} must be a whole number above 0\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$per_page =~ /^\d+$/ and $per_page > 0
MC/DC0%0/2
$per_page =~ /^\d+$/ and $per_page > 0
$per_page =~ /^\d+$/
$per_page > 0
Truth table0%0/3
A and B
A= $per_page =~ /^\d+$/B= $per_page > 0
| |||||||||||||||||||||||||||||
| 173 | unless $per_page =~ /^\d+$/ and $per_page > 0; | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | 0 | ▶ | my @items = $settings->{items} ? @{$settings->{items}} : items_for($dapper->{site}, $settings); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 0 | ▶ | my $total_pages = int((@items + $per_page - 1) / $per_page) || 1; | ||||||||||||||||||||||||||
|
Condition0%0/2
int((@items + $per_page - 1) / $per_page) || 1
MC/DC0%0/1
int((@items + $per_page - 1) / $per_page) || 1
int((@items + $per_page - 1) / $per_page)
Truth table0%0/2
A
A= int((@items + $per_page - 1) / $per_page)
| |||||||||||||||||||||||||||||
| 178 | 0 | my $base = base_url($page->{url}); | |||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | 0 | ▶ | my @urls = map { $_ == 1 ? $page->{url} : "${base}page/$_/" } 1 .. $total_pages; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | 0 | my @pages; | |||||||||||||||||||||||||||
| 183 | 0 | for my $number (1 .. $total_pages) { | |||||||||||||||||||||||||||
| 184 | 0 | ▶ | my $copy = $number == 1 ? $page : { %$page }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | 0 | ▶ | if ($number > 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 187 | 0 | $copy->{url} = $urls[$number - 1]; | |||||||||||||||||||||||||||
| 188 | 0 | delete $copy->{markdown}; | |||||||||||||||||||||||||||
| 189 | 0 | delete $copy->{markdown_url}; | |||||||||||||||||||||||||||
| 190 | 0 | set_filename($dapper, $copy, 1); | |||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | 0 | my $first = ($number - 1) * $per_page; | |||||||||||||||||||||||||||
| 194 | 0 | my $last = $first + $per_page - 1; | |||||||||||||||||||||||||||
| 195 | 0 | ▶ | $last = $#items if $last > $#items; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | $copy->{paginator} = { | ||||||||||||||||||||||||||||
| 198 | items => [ @items > 0 ? @items[$first .. $last] : () ], | ||||||||||||||||||||||||||||
| 199 | page => $number, | ||||||||||||||||||||||||||||
| 200 | per_page => $per_page, | ||||||||||||||||||||||||||||
| 201 | total_pages => $total_pages, | ||||||||||||||||||||||||||||
| 202 | total_items => scalar @items, | ||||||||||||||||||||||||||||
| 203 | previous_url => $number > 1 ? $urls[$number - 2] : undef, | ||||||||||||||||||||||||||||
| 204 | next_url => $number < $total_pages ? $urls[$number] : undef, | ||||||||||||||||||||||||||||
| 205 | first_url => $urls[0], | ||||||||||||||||||||||||||||
| 206 | last_url => $urls[-1], | ||||||||||||||||||||||||||||
| 207 | 0 | ▶ | pages => [ map { { number => $_, url => $urls[$_ - 1] } } 1 .. $total_pages ], | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 208 | }; | ||||||||||||||||||||||||||||
| 209 | 0 | ▶ | $copy->{posts} = $copy->{paginator}->{items} if $page->{generated}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | 0 | push @pages, $copy; | |||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | 0 | return @pages; | |||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | =head2 items_for | ||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | Takes the site and pagination settings, and returns the pages to paginate, | ||||||||||||||||||||||||||||
| 220 | newest first: those in the C<category> or with the C<tag>, or every page with | ||||||||||||||||||||||||||||
| 221 | a category if neither is given. | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | =cut | ||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | 0 | ▶ | sub items_for { | ||||||||||||||||||||||||||
|
Subroutine
items_for: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 226 | 0 | my ($site, $settings) = @_; | |||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | 0 | my @items; | |||||||||||||||||||||||||||
| 229 | 0 | ▶ | if (defined $settings->{category}) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 230 | 0 | ▶ | @items = @{ $site->{categories}->{$settings->{category}} || [] }; | ||||||||||||||||||||||||||
|
Condition0%0/2
$site->{'categories'}{$settings->{'category'}} || []
MC/DC0%0/1
$site->{'categories'}{$settings->{'category'}} || []
$site->{'categories'}{$settings->{'category'}}
Truth table0%0/2
A
A= $site->{'categories'}{$settings->{'category'}}
| |||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||
| 232 | elsif (defined $settings->{tag}) { | ||||||||||||||||||||||||||||
| 233 | 0 | ▶ | @items = @{ $site->{tags}->{$settings->{tag}} || [] }; | ||||||||||||||||||||||||||
|
Condition0%0/2
$site->{'tags'}{$settings->{'tag'}} || []
MC/DC0%0/1
$site->{'tags'}{$settings->{'tag'}} || []
$site->{'tags'}{$settings->{'tag'}}
Truth table0%0/2
A
A= $site->{'tags'}{$settings->{'tag'}}
| |||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||
| 235 | else { | ||||||||||||||||||||||||||||
| 236 | 0 | my %seen; | |||||||||||||||||||||||||||
| 237 | 0 | @items = grep { !$seen{$_}++ } map { @{ $site->{categories}->{$_} } } sort keys %{$site->{categories}}; | |||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | 0 | return sort { $b->{date} <=> $a->{date} } @items; | |||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | =head2 base_url | ||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | Takes a URL and returns the directory the further pages go in: | ||||||||||||||||||||||||||||
| 246 | C</blog/> stays C</blog/>, and C</archive.html> becomes C</archive/>. | ||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | =cut | ||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | 0 | ▶ | sub base_url { | ||||||||||||||||||||||||||
|
Subroutine
base_url: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 251 | 0 | my ($url) = @_; | |||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | 0 | ▶ | return $url if $url =~ m{/$}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 254 | 0 | $url =~ s{/index\.[^./]+$}{/}; | |||||||||||||||||||||||||||
| 255 | 0 | ▶ | return $url if $url =~ m{/$}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 256 | 0 | $url =~ s{\.[^./]+$}{}; | |||||||||||||||||||||||||||
| 257 | 0 | return "$url/"; | |||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | =head2 set_filename | ||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||
| 262 | Takes the Dapper object and a page with a C<url>, and sets the page's | ||||||||||||||||||||||||||||
| 263 | C<filename> and C<dirname> from it. A URL ending in C</> is written as an | ||||||||||||||||||||||||||||
| 264 | index file. | ||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | =cut | ||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | 0 | ▶ | sub set_filename { | ||||||||||||||||||||||||||
|
Subroutine
set_filename: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 269 | 0 | my ($dapper, $page, $is_index) = @_; | |||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||
| 271 | 0 | my $path = $page->{url}; | |||||||||||||||||||||||||||
| 272 | 0 | ▶ | $path .= "index$page->{extension}" if $path =~ m{/$}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 273 | 0 | $page->{filename} = canonpath(catfile($dapper->{output}, $path)); | |||||||||||||||||||||||||||
| 274 | 0 | (my $dir = $page->{filename}) =~ s{[^/]*$}{}; | |||||||||||||||||||||||||||
| 275 | 0 | $page->{dirname} = $dir; | |||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||
| 278 | 32 | 1; | |||||||||||||||||||||||||||