| 1 | package App::Dapper; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | App::Dapper - A publishing tool for static websites. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 190 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 190 | ▶ | use open ':std', ':encoding(UTF-8)'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 190 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 190 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 190 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 190 | ▶ | use vars '$VERSION'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 190 | ▶ | use Exporter qw(import); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 190 | ▶ | use Template::Alloy; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 190 | ▶ | use JSON (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 190 | ▶ | use App::Dapper::Markdown; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 190 | ▶ | use App::Dapper::Schema; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 190 | ▶ | use App::Dapper::Publish; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 190 | ▶ | use App::Dapper::Collections; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 190 | ▶ | use App::Dapper::Check; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 190 | ▶ | use App::Dapper::MCP; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 190 | ▶ | use App::Dapper::Agents; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 190 | ▶ | use App::Dapper::Deploy; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 190 | ▶ | use App::Dapper::Images; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 190 | ▶ | use App::Dapper::Import; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 190 | ▶ | use Scalar::Util (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 190 | ▶ | use YAML::PP qw/ LoadFile /; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 190 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 190 | ▶ | use File::Spec::Functions qw/ canonpath catfile /; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 190 | ▶ | use File::Basename qw/ basename /; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 190 | ▶ | use File::Find (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 190 | ▶ | use Cwd qw/ abs_path /; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 190 | ▶ | use DateTime; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 190 | ▶ | use DateTime::TimeZone; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 190 | ▶ | use App::Dapper::Init; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 190 | ▶ | use App::Dapper::Utils; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 190 | ▶ | use App::Dapper::Defaults; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 190 | ▶ | use App::Dapper::Filters; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 190 | my $DEFAULT_PORT = 8000; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | Version 1.00 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 190 | our $VERSION = '1.10'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 190 | our @EXPORT = qw($VERSION); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | B<Dapper> allows you to transform simple text files into static websites. By installing the App::Dapper Perl module, an executable named C<dapper> will be available to you in your terminal window. You can use this executable in a number of ways: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | # Initialize the current directory with a fresh skeleton of a site | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | $ dapper [-solc] init | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | # ...or with a complete starter blog | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | $ dapper init --template blog | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | # Build the site | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | $ dapper [-solc] build | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | # Serve the site locally at http://localhost:8000 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | $ dapper [-solcp] serve | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | # Rebuild the site if anything (source, layout dirs; config file) changes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | $ dapper [-solc] watch | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | # Check the site for problems, without touching the output directory | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | $ dapper [-solc] check [--json] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | # Build, check and publish the site (to S3, GitHub Pages, or a command) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | $ dapper deploy [target] [--dry-run] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | # Let AI assistants read, write, check and build the site over MCP | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | $ dapper -C /path/to/site mcp | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # Get help on usage and switches | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | $ dapper -h | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | # Print the version | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | $ dapper -v | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | Additionally, B<Dapper> may be used as a perl module directly from a script. Examples: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | use App::Dapper; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | # Create a Dapper object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | my $d = App::Dapper->new(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | # Initialize a new website in the current directory | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | $d->init(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | # Build the site | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | $d->build(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | # Serve the site locally at http://localhost:8000 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | $d->serve(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | Dapper helps you build static websites. To get you started, you can use the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | C<dapper init> command to initialize a directory. After running this command, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | the following directory structure will be created: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | _config.yml | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | _layout/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | index.html | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | _source/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | index.md | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | In that same directory, you may then build the site using the C<dapper build> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | command, which will combine the source files and the layout files and place | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | the results in the output directory (default: C<_output>). After you build | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | the default site, you'll then have the following directory structure: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | _config.yml | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | _layout/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | index.html | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | _source/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | index.md | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | _output/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | index.html | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | To see what your website looks like, run the C<dapper serve> command which | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | will spin up a development webserver and serve the static files located in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | the output directory (default: C<_output>) at L<http://localhost:8000>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | Now, let's walk through each file: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | =item B<_config.yml> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | The configuration file is a YAML file that specifies key configuration | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | elements for your static website. The default configuration file is as | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | follows: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | --- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | name : My Site | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | If you want to use a separate source, layout, or output directory, you may | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | specify it in this file. For instance: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | --- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | name : My Site | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | source : _source | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | layout : _layout | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | output : _output | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | Directories given on the command line take precedence over the ones in the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | configuration file, which take precedence over the defaults. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | All of the configurations in this file are available in layout templates | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | under the C<site> namespace. For instance, C<name> in the configuration file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | may be used in a template as follows: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | [% site.name %] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | =item B<_source/index.md> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | A sample markdown file is available in the _source directory. Contents: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | --- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | layout: index | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | title: Welcome | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | --- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | Hello world. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | There are a few things to note about this file: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | =item 1. There is a YAML configuration block (the "front matter") at the start of the file. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | =item 2. The I<layout> configuration specifies which layout to use. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | =item 3. The C<index> layout indicates that C<_layout/index.html> should be used. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | =item 4. The C<title> configuration is the name of the post/page. It is optional. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | =item 5. All of the configurations may be used in the corresponding layout file. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | <!-- Example use of "title" in a layout file --> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | <h1>[% page.title %]</h1> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | Files in the source directory that do not start with front matter (images, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | PDFs, plain text files and so on) are copied to the output directory as they | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | are. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | A page's content is not run as template code unless the page sets | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | C<template: true>; layouts always are. C<templates_in_content: true> in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | C<_config.yml> restores the behavior of Dapper before 1.0, where all content | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | and C<_config.yml> values were templates too. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | A C<_schema.yml> file in a source directory describes the front matter its | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | pages must have; see L<App::Dapper::Schema>. YAML and JSON files in C<_data> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | are available as C<site.data>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | =item B<_layout/index.html> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | Layout files are processed using the template language provided by | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | L<Template::Alloy> (the Template Toolkit mini-language). The initial layout | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | file that is given after you run the C<dapper init> command, is this: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | <!DOCTYPE html> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | <html lang="en"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | <head> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | <meta charset="utf-8"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | <title>[% page.title %]</title> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | </head> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | <body> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | [% page.content %] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | </body> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | </html> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | The main content of the text file that is being rendered with this template | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | is available using C<[% page.content %]>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | Definitions specified in the C<_config.yml> file can be referenced under the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | "site" namespace (e.g. C<[% site.name %]>). Definitions specified in the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | front matter of source files can be referenced under the "page" namespace | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | (e.g. C<[% page.title %]>). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | =item B<_output/index.html> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | The output file that is created is a mix of the input file and the layout that | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | is specified by the input file. For the default site, the following output | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | file is created: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | <!DOCTYPE html> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | <html lang="en"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | <head> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | <meta charset="utf-8"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | <title>Welcome</title> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | </head> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | <body> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | <p>Hello world.</p> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | </body> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | </html> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | =head2 Variables | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | The following variables are available in layouts and source files. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | =item B<site.*> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | Everything defined in C<_config.yml>, plus: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | site.time The time the build started (a DateTime) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | site.pages Every page, in source path order | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | site.categories A hash of category name to its pages, sorted by date | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | site.tags A hash of tag to its pages, sorted by date | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | site.data The contents of the files in _data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | site.category_pages, site.tag_pages URLs of generated list pages | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | site.source The resolved source directory | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | site.output The resolved output directory | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | site.layout The resolved layout directory | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | site.urlpattern Default URL pattern (/:category/:year/:month/:slug/) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | site.extension Default output extension (.html) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | site.ignore Patterns of top-level files not copied to the output | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | =item B<page.*> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | Everything defined in the page's front matter, plus: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | page.content The rendered body of the page | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | page.excerpt The first paragraph of a markdown page | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | page.url The URL of the page, relative to the site root | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | page.slug The title, slugified (or the file name if no title) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | page.id A number unique to the page within a build | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | page.date The page date (front matter, or the file's mtime) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | page.year, page.month, page.day, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | page.hour, page.minute, page.second Parts of page.date, zero padded | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | page.filename The output file the page is written to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | page.dirname The directory of page.filename | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | page.source_file_extension The source file's extension (e.g. .md) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | page.seo Tags for <head>: description, canonical, Open Graph, JSON-LD | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | page.markdown_url The URL of the page's Markdown copy, if it has one | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | page.posts On a generated category or tag page: its pages | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | paginator On a paginated page; see App::Dapper::Collections | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | =head2 URLs and output files | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | Pages with C<categories> or their own C<urlpattern> are written to the path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | their URL describes. The pattern may use C<:category>, C<:year>, C<:month>, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | C<:day>, C<:hour>, C<:minute>, C<:second> and C<:slug>. A URL ending in C</> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | is written as C<index> plus the page extension inside that directory. Other | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | pages keep the path of their source file, with the page extension. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | =head2 Generated files | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | After the pages, Dapper writes a sitemap, a feed (if C<feed> is set), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | Markdown copies of pages and C<llms.txt> (see L<App::Dapper::Publish>), can | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | generate category and tag pages and paginate lists (see | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | L<App::Dapper::Collections>), and can build a search index with Pagefind. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | Files that an earlier build wrote and this one did not are removed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | =head2 Options | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | B<Dapper> provides a number of optional command line switches: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | =item B<-s>, B<--source>=I<source directory> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | Specify the directory containing source files to process. If this command line option is not present, it defaults to the C<source> setting in the config file, or "_source". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | =item B<-o>, B<--output>=I<output directory> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | Specify the directory to place the output files in. If this command line option is not present, it defaults to the C<output> setting in the config file, or "_output". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | =item B<-l>, B<--layout>=I<layout directory> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | Specify the directory containing layout files. If this command line option is not present, it defaults to the C<layout> setting in the config file, or "_layout". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | =item B<-c>, B<--config>=I<config file> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | Specify the config file name to use. If this command line option is not present, it defaults to "_config.yml". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | =item B<-p>, B<--port>=I<port> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | Specify the port to use for the serve command. Defaults to 8000. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | =item B<-q>, B<--quiet> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | Only print errors. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | =item B<-C>, B<--directory>=I<directory> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | Run in this directory instead of the current one. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | =item B<-t>, B<--template>=I<name> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | For the init command: the starter project to create, C<default> or C<blog>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | =item B<--json> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | For the check command: print the report as JSON. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | =item B<-h>, B<--help> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | Get help on available commands and options. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | =item B<-v>, B<--version> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | Print the version and exit. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | Dapper may be used directly from a script as well. The following methods are available: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | =head2 new | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | Create a new B<Dapper> object. Example: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | my $d = App::Dapper->new(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | Alternatively, the source dir, output dir, layout dir, and configuration file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | may be specified. Any of them may be C<undef>, in which case the value from | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | the configuration file (or the default) is used. Example: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | my $d = App::Dapper->new("_source", "_output", "_layout", "_config.yml"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | After creating a B<Dapper> object, the following hash elements may be accessed: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | use App::Dapper; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | my $d = App::Dapper->new(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | print "Source directory: $d->{source}\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | print "Output directory: $d->{output}\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | print "Layout directory: $d->{layout}\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | print "Config file: $d->{config}\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | print "Object instantiation time: $d->{site}->{time}\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | The directories are updated from the configuration file when the site is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | built or served. Set C<< $d->{quiet} >> to a true value to suppress progress | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | messages. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 167 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 167 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 167 | my ($source, $output, $layout, $config) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 167 | ▶ | my $self = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | created => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | quiet => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | explicit => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | source => defined $source, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | output => defined $output, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | layout => defined $layout, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | config => defined $config, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | source => defined $source ? $source : "_source", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | output => defined $output ? $output : "_output", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | layout => defined $layout ? $layout : "_layout", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | config => defined $config ? $config : "_config.yml", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 167 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 167 | $self->reset_site(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 3 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | =head2 init | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | Initializes a new skeleton project in the current directory of the calling | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | script, using the source dir, layout dir and config file given to L</new>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | Nothing is written if any of the files already exist. Example usage: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | use App::Dapper; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | my $d = App::Dapper->new(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | $d->init(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | Set C<< $d->{template} >> to C<blog> first for a complete starter blog (see | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | L<App::Dapper::Init>). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 0 | ▶ | sub init { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 0 | local $App::Dapper::Utils::QUIET = $self->{quiet}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | my $notes = App::Dapper::Init::init( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | $self->{source}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | $self->{output}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | $self->{layout}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | $self->{config}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | $self->{template} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | # Explain the new project to AI coding agents | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 0 | for my $file (App::Dapper::Agents::update($self, $notes)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 0 | $self->_log("Creating $file"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 0 | $self->_log("Project initialized."); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | =head2 build | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | Build the site. Example: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | use App::Dapper; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | my $d = App::Dapper->new(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | $d->build(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | When the site is built, it is done in three steps: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 1. Parse. In this step, the configuration file is read. In addition, all the source files in the source directory as well as the layout files in the layout directory are read and stored in the site hash. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 2. Transform. Combine source and layout files. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 3. Render. Save output files to the output directory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | A Dapper object may be built any number of times; each build starts fresh. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 3 | ▶ | sub build { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
build: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 3 | my($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 3 | $self->{problems} = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 3 | $self->{written} = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 3 | $self->{page_owner} = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 3 | $self->{held} = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 3 | $self->parse(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 3 | $self->transform(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 3 | $self->render(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | 3 | $self->_log("Project built."); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 3 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | # sub parse - Parse the source directory, config file, and templates. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 3 | ▶ | sub parse { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 3 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | # load the defaults and the project file, and resolve the directories | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 3 | $self->read_project(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | # read the layouts, expanding layouts that are wrapped in other layouts | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 3 | $self->read_templates(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | # sub transform - Walk the source directory and record every page (and every | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | # file to copy as it is) in the site hash. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 3 | ▶ | sub transform { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
transform: called CC=4 SCAR=15.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 3 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 3 | ▶ | die "error: source directory \"$self->{source}\" does not exist\n" unless -d $self->{source}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 3 | $self->{schema_errors} = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | # recurse through the source tree, mapping each file to its output path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 3 | $self->walk($self->{source}, $self->{output}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 3 | my @errors = @{$self->{schema_errors}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | die "error: " . scalar(@errors) . " problem" . (@errors == 1 ? '' : 's') . " with front matter (see the _schema.yml files):\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 0 | ▶ | . join('', map { " $_\n" } @errors) if @errors; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | # category pages, tag pages and pagination | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 3 | ▶ | $self->attempt($self->{config}, sub { App::Dapper::Collections::generate($self) }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | # sub render - Combine each page with its layout and write it to the output | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | # directory, then copy the files that are not pages. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 3 | ▶ | sub render { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
render: called CC=10 SCAR=26.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | 3 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | # Template::Alloy's built-in json method returns UTF-8 bytes, which would | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | # be encoded a second time when the page is written. Give it encoders | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | # that return characters instead. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | 3 | $Template::Alloy::VMethod::JSON = JSON->new->allow_nonref->allow_unknown->allow_blessed->convert_blessed->canonical; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | 3 | $Template::Alloy::VMethod::JSONP = JSON->new->allow_nonref->allow_unknown->allow_blessed->convert_blessed->canonical->pretty; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | my $tt = Template::Alloy->new({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | INCLUDE_PATH => $self->{layout}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | ANYCASE => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | ENCODING => 'utf8', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | FILTERS => App::Dapper::Filters::filters(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 3 | ▶ | EVAL_PERL => $ENV{EVAL_PERL} || 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$ENV{'EVAL_PERL'} || 0
MC/DC0%0/1
$ENV{'EVAL_PERL'} || 0
$ENV{'EVAL_PERL'}
Truth table50%1/2
A
A= $ENV{'EVAL_PERL'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | # Work out what layouts can show about each page before any are rendered | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 3 | for my $page (@{$self->{site}->{pages}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | $page->{markdown_url} = App::Dapper::Publish::twin_url($page) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | 3 | ▶ | if App::Dapper::Publish::has_twin($self->{site}, $page); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | 3 | $page->{seo} = App::Dapper::Publish::seo($self->{site}, $page); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 3 | for my $page (@{$self->{site}->{pages}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 3 | ▶ | $self->attempt($page->{source}, sub { $self->render_page($tt, $page) }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | # copy source files that have no front matter (images, etc.) as they are | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | 3 | for my $file (@{$self->{static_files}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | 0 | my $owner = $self->{page_owner}->{canonpath($file->{output})}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | 0 | ▶ | if (defined $owner) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | 0 | $self->problem('error', $file->{source}, "$file->{source} and $owner both write " . canonpath($file->{output})); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | 0 | $self->record_written(App::Dapper::Utils::copy_recursive($file->{source}, $file->{output})); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | 0 | $self->_log("Copied $file->{source}"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | # copy additional files and directories | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 3 | $self->copy(".", $self->{output}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | # sitemap, feed and llms.txt | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | 3 | ▶ | $self->attempt($self->{config}, sub { $self->write_generated() }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | # image sizes, responsive copies and lazy loading (with "images" set) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | 3 | ▶ | $self->attempt($self->{config}, sub { App::Dapper::Images::process($self) }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | # with live reload on, a new value here tells open pages to reload | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | 3 | ▶ | if ($self->{live_reload}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | 0 | $self->write_output(catfile($self->{output}, '.dapper-reload'), time() . '-' . int(rand(1_000_000)) . "\n"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | # remove what earlier builds wrote that this one did not | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | 3 | ▶ | $self->clean_output() unless $self->{collect}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | # search index | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | 3 | ▶ | $self->run_search() unless $self->{collect}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | # sub run_search - With "search: true", run Pagefind (https://pagefind.app) over | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | # the output directory to build a search index. "search_command" can name a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | # different command, such as "npx -y pagefind". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | 3 | ▶ | sub run_search { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run_search: called CC=8 SCAR=37.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | 3 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | 3 | my $site = $self->{site}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | 3 | ▶ | return unless $site->{search} and App::Dapper::Publish::enabled($site, 'search'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$site->{"search"} and App::Dapper::Publish::enabled($site, "search")
MC/DC0%0/2
$site->{"search"} and App::Dapper::Publish::enabled($site, "search")
$site->{"search"}
App::Dapper::Publish::enabled($site, "search")
Truth table33%1/3
A and B
A= $site->{"search"}B= App::Dapper::Publish::enabled($site, "search")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | 0 | ▶ | my @command = defined $site->{search_command} ? split(' ', $site->{search_command}) : ('pagefind'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | 0 | ▶ | my $found = $command[0] =~ m{/} ? -x $command[0] : grep { -x catfile($_, $command[0]) } File::Spec->path(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 0 | ▶ | if (not $found) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | $self->problem('warning', $self->{config}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | 0 | "search: true needs Pagefind; install it (see https://pagefind.app) or set search_command"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | 0 | $self->_log("Building the search index with @command"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | 0 | ▶ | my @quiet = $self->{quiet} ? ('--quiet') : (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | system(@command, '--site', $self->{output}, @quiet) == 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | 0 | ▶ | or $self->problem('warning', $self->{config}, "@command did not finish (exit status " . ($? >> 8) . ")"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | # sub clean_output - Remove files that an earlier build wrote to the output | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | # directory but this build did not (the output of a page that was renamed or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | # deleted, say). Only files Dapper itself wrote are ever removed: the list is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | # kept in .dapper/manifest.json in the project directory. "clean: false" in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | # the project file turns this off. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 3 | ▶ | sub clean_output { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clean_output: called CC=17 SCAR=45.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | 3 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 3 | ▶ | return unless App::Dapper::Publish::enabled($self->{site}, 'clean'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | 3 | my $manifest_file = catfile('.dapper', 'manifest.json'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | 3 | my $output = abs_path($self->{output}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | 3 | ▶ | return unless defined $output; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | 3 | my $manifest = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | 3 | ▶ | if (-f $manifest_file) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | 0 | ▶ | $manifest = eval { JSON->new->decode(App::Dapper::Utils::read_file($manifest_file)) } || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
eval {
do {
'JSON'->new->decode(App::Dapper::Utils::read_file($manifest_file))
}
} || {}
MC/DC0%0/1
eval {
do {
'JSON'->new->decode(App::Dapper::Utils::read_file($manifest_file))
}
} || {}
eval {
do {
'JSON'->new->decode(App::Dapper::Utils::read_file($manifest_file))
}
}
Truth table0%0/2
A
A= eval {
do {
'JSON'->new->decode(App::Dapper::Utils::read_file($manifest_file))
}
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | 0 | ▶ | $manifest = {} unless ref $manifest eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | 3 | my $old = $manifest->{$output}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | 3 | my $removed = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | 3 | my %dirs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | 3 | ▶ | if (ref $old eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | 0 | for my $path (@$old) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | 0 | ▶ | next if $self->{written}->{$path}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | 0 | ▶ | next if $path =~ m{(?:^|/)\.\.(?:/|$)} or $path =~ m{^/}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$path =~ m[(?:^|/)\.\.(?:/|$)] or $path =~ m[^/]
MC/DC0%0/2
$path =~ m[(?:^|/)\.\.(?:/|$)] or $path =~ m[^/]
$path =~ m[(?:^|/)\.\.(?:/|$)]
$path =~ m[^/]
Truth table0%0/3
A or B
A= $path =~ m[(?:^|/)\.\.(?:/|$)]B= $path =~ m[^/]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | 0 | my $file = catfile($self->{output}, $path); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | 0 | ▶ | next unless -f $file; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | 0 | ▶ | unlink $file or next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | 0 | $removed++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | 0 | (my $dir = $path) =~ s{/?[^/]*$}{}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | 0 | ▶ | while (length $dir) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | 0 | $dirs{$dir} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | 0 | $dir =~ s{/?[^/]*$}{}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | # Remove directories the removed files leave empty, deepest first | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | 0 | for my $dir (sort { length $b <=> length $a } keys %dirs) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | 0 | rmdir catfile($self->{output}, $dir); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | 3 | ▶ | $self->_log("Removed $removed file" . ($removed == 1 ? '' : 's') . " left over from an earlier build") if $removed; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | 3 | $manifest->{$output} = [ sort keys %{$self->{written}} ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | 3 | App::Dapper::Utils::write_file($manifest_file, JSON->new->canonical->pretty->encode($manifest)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | # sub live_reload_script - The script added to pages while "dapper serve" is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | # running. It asks for /.dapper-reload every second and reloads the page when | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | # a new build changes it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | 0 | ▶ | sub live_reload_script { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
live_reload_script: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | 0 | return <<'HTML'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | <script> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | (function () { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | var last = null; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | function poll() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | fetch('/.dapper-reload?' + Date.now(), { cache: 'no-store' }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | .then(function (r) { return r.ok ? r.text() : last; }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | .then(function (t) { if (last !== null && t !== last) { location.reload(); } last = t; }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | .catch(function () {}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | .then(function () { setTimeout(poll, 1000); }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | poll(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | })(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | </script> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | HTML | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | # sub write_generated - Write the files Dapper makes for the whole site: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | # redirects, the sitemap, the feed, and llms.txt and llms-full.txt. A page that writes the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | # same file wins, with a warning. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | 3 | ▶ | sub write_generated { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write_generated: called CC=11 SCAR=31.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | 3 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | 3 | my $site = $self->{site}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | 3 | my @pages = @{$site->{pages}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | 3 | my %taken = map { $_->{filename} => 1 } @pages; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | 3 | ▶ | my $has_url = defined $site->{url} && length $site->{url}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
defined $site->{'url'} && length $site->{'url'}
MC/DC0%0/2
defined $site->{'url'} && length $site->{'url'}
defined $site->{'url'}
length $site->{'url'}
Truth table33%1/3
A && B
A= defined $site->{'url'}B= length $site->{'url'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | 6 | ▶ | my $write = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | 6 | my ($path, $content) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | 6 | my $file = canonpath(catfile($self->{output}, $path)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | 6 | ▶ | if ($taken{$file}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | 0 | $self->problem('warning', $file, "a page in the source directory already writes $file, so Dapper did not generate one"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | 6 | $self->write_output($file, $content); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | 6 | $self->_log("Wrote $file"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | 3 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | 3 | my $redirects = App::Dapper::Publish::redirects($site); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | 3 | for my $from (sort keys %$redirects) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | 0 | my $file = canonpath(catfile($self->{output}, App::Dapper::Publish::redirect_path($from))); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | 0 | ▶ | if ($taken{$file}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | 0 | $self->problem('warning', $file, "a page is still at $from, so the redirect from it to $redirects->{$from} was not written"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | 0 | $self->write_output($file, App::Dapper::Publish::redirect_page($site, $redirects->{$from})); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | 0 | $self->{page_owner}->{$file} = "the redirect from $from"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | 0 | $taken{$file} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | 3 | ▶ | if (App::Dapper::Publish::enabled($site, 'llms_txt')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | 3 | my @twins = grep { $_->{markdown_url} } @pages; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | 3 | ▶ | if (@twins) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | 3 | $write->('llms.txt', App::Dapper::Publish::llms_txt($site, \@twins)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | 3 | $write->('llms-full.txt', App::Dapper::Publish::llms_full_txt($site, \@twins)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | 3 | ▶ | if (App::Dapper::Publish::enabled($site, 'sitemap')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | 3 | ▶ | if ($has_url) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | 0 | $write->('sitemap.xml', App::Dapper::Publish::sitemap($site, \@pages)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | elsif ($self->{configured}->{sitemap}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | 0 | $self->problem('warning', $self->{config}, "the sitemap needs the site's address; set url in $self->{config}"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | 3 | ▶ | if (my $settings = App::Dapper::Publish::feed_settings($site)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | 0 | ▶ | if ($has_url) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | 0 | my $pages = App::Dapper::Publish::feed_pages($site, $settings); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | 0 | $write->($settings->{path}, App::Dapper::Publish::feed($site, $settings, $pages)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | 0 | $self->problem('warning', $self->{config}, "the feed needs the site's address; set url in $self->{config}"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | # sub render_page - Render one page with its layout and write it to disk. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | # Layouts are always processed as templates. The page's content is processed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | # as a template only if the page sets "template: true". With | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | # "templates_in_content: true" in the project file, Dapper instead works as it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | # did before 1.0: the layout is rendered, and then the result is rendered a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | # second time, so that template code in content and in site variables runs. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | 3 | ▶ | sub render_page { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
render_page: called CC=14 SCAR=35.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | 3 | my ($self, $tt, $page) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | 3 | ▶ | $page->{layout} = "index" unless $page->{layout}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | 3 | my $layout = $self->{layout_content}->{$page->{layout}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | 3 | ▶ | die "error: $page->{source} uses the layout \"$page->{layout}\", but there is no such file in $self->{layout}\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | unless defined $layout; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | my %vars = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | site => $self->{site}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | page => $page, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | paginator => $page->{paginator}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | 3 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | 3 | my $output; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | 3 | ▶ | if ($self->{site}->{templates_in_content}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | 0 | my $first; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | 0 | ▶ | $tt->process(\$layout, \%vars, \$first) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | || die "error: could not process $page->{source} with layout $page->{layout}: " . $tt->error() . "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | 0 | ▶ | $tt->process(\$first, \%vars, \$output) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | || die "error: could not process $page->{source} with layout $page->{layout} (2nd pass): " . $tt->error() . "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | 3 | ▶ | if ($page->{template}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | 0 | my $content; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | 0 | ▶ | $tt->process(\$page->{content}, \%vars, \$content) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | || die "error: could not process the content of $page->{source}: " . $tt->error() . "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | 0 | $page->{content} = $content; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | 3 | ▶ | $tt->process(\$layout, \%vars, \$output) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | || die "error: could not process $page->{source} with layout $page->{layout}: " . $tt->error() . "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | 3 | ▶ | if ($self->{live_reload} and App::Dapper::Publish::is_html($page)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"live_reload"} and App::Dapper::Publish::is_html($page)
MC/DC0%0/2
$self->{"live_reload"} and App::Dapper::Publish::is_html($page)
$self->{"live_reload"}
App::Dapper::Publish::is_html($page)
Truth table33%1/3
A and B
A= $self->{"live_reload"}B= App::Dapper::Publish::is_html($page)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | 0 | my $script = live_reload_script(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | 0 | ▶ | $output =~ s{(</body>)}{$script$1}i or $output .= $script; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | 3 | my $owner = $self->{page_owner}->{$page->{filename}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | 3 | ▶ | die "error: $page->{source} and $owner both write $page->{filename}\n" if defined $owner; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | 3 | $self->{page_owner}->{$page->{filename}} = $page->{source}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | 3 | $self->write_output($page->{filename}, $output); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | 3 | $self->_log("Wrote $page->{filename}"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 822 | 3 | ▶ | if ($page->{markdown_url}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 823 | 3 | my $twin = App::Dapper::Publish::twin_path($page); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | 3 | $self->write_output($twin, App::Dapper::Publish::twin($self->{site}, $page)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 825 | 3 | $self->_log("Wrote $twin"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 826 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 828 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | # sub write_output - Write a file to the output directory and remember that | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 830 | # Dapper wrote it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 831 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 832 | 12 | ▶ | sub write_output { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write_output: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 833 | 12 | my ($self, $filename, $content) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 834 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 835 | 12 | App::Dapper::Utils::write_file($filename, $content); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 836 | 12 | $self->record_written($filename); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 837 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 838 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 839 | # sub record_written - Remember files written to the output directory, so that | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 840 | # files left over from earlier builds can be found. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 841 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 842 | 12 | ▶ | sub record_written { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
record_written: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 843 | 12 | my ($self, @files) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 845 | 12 | for my $file (@files) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 846 | 12 | my $relative = File::Spec->abs2rel($file, $self->{output}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 847 | 12 | $self->{written}->{ join('/', File::Spec->splitdir($relative)) } = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 848 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 849 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 850 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 851 | # sub attempt - Run a step of the build for a file. Normally an error stops the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 852 | # build. When collecting problems (as "dapper check" does), the error is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 853 | # recorded and the build carries on. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 854 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 855 | 15 | ▶ | sub attempt { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
attempt: called CC=3 SCAR=17.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 856 | 15 | my ($self, $file, $code) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 857 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 858 | 15 | ▶ | return $code->() unless $self->{collect}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 859 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 860 | 0 | ▶ | eval { $code->(); 1 } or $self->problem('error', $file, $@); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 861 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 862 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 863 | # sub problem - Record a problem found during the build. Errors stop the build | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 864 | # unless problems are being collected; warnings are printed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 865 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 866 | 0 | ▶ | sub problem { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
problem: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 867 | 0 | my ($self, $severity, $file, $message) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 868 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 869 | 0 | $message =~ s/^(?:error|warning): //; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 870 | 0 | $message =~ s/\s+\z//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 871 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 872 | 0 | ▶ | if ($self->{collect}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 873 | 0 | push @{$self->{problems}}, { severity => $severity, file => $file, message => $message }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 874 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 875 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 876 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 877 | 0 | ▶ | die "error: $message\n" if $severity eq 'error'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 878 | 0 | warn "warning: $message\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 879 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 880 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 881 | =head2 check | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 882 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 883 | Build the site into a temporary directory and return a report of every | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 884 | problem found, without touching the output directory. See | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 885 | L<App::Dapper::Check>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 886 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 887 | my $report = $d->check(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 888 | print "ok\n" if $report->{ok}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 889 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 890 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 891 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 892 | 0 | ▶ | sub check { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 893 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 894 | 0 | return App::Dapper::Check::run($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 895 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 896 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 897 | =head2 agents | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 898 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 899 | Write or update C<AGENTS.md> (and a C<CLAUDE.md> if there isn't one), which | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 900 | explains the project to AI coding agents. See L<App::Dapper::Agents>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 901 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 902 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 903 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 904 | 0 | ▶ | sub agents { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
agents: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 905 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 906 | 0 | for my $file (App::Dapper::Agents::update($self)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 907 | 0 | $self->_log("Wrote $file"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 908 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 909 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 910 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 911 | =head2 deploy | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 912 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 913 | Build, check and publish the site to a target set under C<deploy> in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 914 | C<_config.yml> (Amazon S3, GitHub Pages, or a command). Takes the target name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 915 | (optional if there is only one) and options: C<dry_run>, C<force>, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 916 | C<no_build>. See L<App::Dapper::Deploy>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 917 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 918 | $d->deploy('s3', dry_run => 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 919 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 920 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 921 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 922 | 0 | ▶ | sub deploy { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
deploy: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 923 | 0 | my ($self, $target, %options) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 924 | 0 | return App::Dapper::Deploy::run($self, $target, %options); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 925 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 926 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 927 | =head2 import_from | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 928 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 929 | Import the pages of another site into the source directory. Takes the kind | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 930 | of site (C<wordpress>, C<jekyll>, C<hugo> or C<medium>), the file or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 931 | directory to import, and options: C<to> (the directory for posts, default | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 932 | C<blog>) and C<dry_run>. See L<App::Dapper::Import>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 933 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 934 | $d->import_from('wordpress', 'export.xml'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 935 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 936 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 937 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 938 | 0 | ▶ | sub import_from { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import_from: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 939 | 0 | my ($self, $kind, $from, %options) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 940 | 0 | return App::Dapper::Import::run($self, $kind, $from, %options); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 941 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 942 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 943 | =head2 mcp | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 944 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 945 | Run a Model Context Protocol server on standard input and output, so that AI | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 946 | assistants can read, write, build and check the site. See | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 947 | L<App::Dapper::MCP>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 948 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 949 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 950 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 951 | 0 | ▶ | sub mcp { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mcp: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 952 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 953 | 0 | App::Dapper::MCP::serve($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 954 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 955 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 956 | =head2 serve | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 957 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 958 | Serve the site locally. Pass in the port number. The port number will be used | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 959 | to serve the site contents from the output directory like this: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 960 | http://localhost:<port>. Here is an example, using the default port 8000: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 961 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 962 | use App::Dapper; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 963 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 964 | my $d = App::Dapper->new(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 965 | $d->serve("8000"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 966 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 967 | The following is equivalent: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 968 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 969 | $d->serve(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 970 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 971 | This method only serves what is already in the output directory (as read from | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 972 | the project file, if there is one); it does not build the site. The C<dapper | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 973 | serve> command builds and watches the site in a separate process while it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 974 | serves. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 975 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 976 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 977 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 978 | 0 | ▶ | sub serve { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
serve: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 979 | 0 | my($self, $port) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 980 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 981 | 0 | require Net::HTTPServer; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 982 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 983 | 0 | ▶ | $port = $DEFAULT_PORT unless $port; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 984 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 985 | 0 | $self->read_project(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 986 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 987 | 0 | print "Starting webserver at http://localhost:$port\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 988 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 989 | my $s = Net::HTTPServer->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 990 | port=>$port, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 991 | docroot=>$self->{output}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 992 | 0 | type=>"forking", | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 993 | log=>"STDOUT", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 994 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 995 | 0 | ▶ | $s->Start() or die "error: could not start the webserver on port $port\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 996 | 0 | $s->Process(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 997 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 998 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 999 | =head2 watch | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1000 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1001 | Build the site, then rebuild it whenever a file in the project changes, is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1002 | added, or is removed. The output directory and dot files are not watched. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1003 | Errors in a rebuild are reported without stopping the watch. Pass the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1004 | polling interval in seconds (default: 1). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1005 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1006 | $d->watch(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1007 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1008 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1009 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1010 | 0 | ▶ | sub watch { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
watch: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1011 | 0 | my ($self, $interval) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1012 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1013 | 0 | ▶ | $interval = 1 unless $interval; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1014 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1015 | 0 | my $previous; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1016 | 0 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1017 | 0 | my $current = $self->snapshot(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1018 | 0 | ▶ | if (not defined $previous or not _same_snapshot($previous, $current)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $previous and _same_snapshot($previous, $current)
MC/DC0%0/2
defined $previous and _same_snapshot($previous, $current)
defined $previous
_same_snapshot($previous, $current)
Truth table0%0/3
A and B
A= defined $previousB= _same_snapshot($previous, $current)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1019 | 0 | ▶ | eval { $self->build(); 1 } or warn $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1020 | 0 | $previous = $self->snapshot(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1021 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1022 | 0 | sleep $interval; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1023 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1024 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1025 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1026 | =head2 snapshot | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1027 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1028 | Returns a hash reference of every watched file in the project mapped to its | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1029 | modification time and size. Used by L</watch> to detect changes. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1030 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1031 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1032 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1033 | 0 | ▶ | sub snapshot { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
snapshot: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1034 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1035 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1036 | 0 | my $output = abs_path($self->{output}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1037 | 0 | my %files; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1038 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1039 | File::Find::find({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1040 | no_chdir => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1041 | 0 | ▶ | wanted => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1042 | 0 | my $path = $File::Find::name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1043 | 0 | my $name = basename($path); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1044 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1045 | 0 | ▶ | if (-d $path) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1046 | 0 | ▶ | return if $path eq '.'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1047 | 0 | my $abs = abs_path($path); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1048 | 0 | ▶ | $File::Find::prune = 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
$name =~ /^\./ or defined $output and defined $abs and $abs eq $output
defined $output and defined $abs and $abs eq $output
defined $output and defined $abs
MC/DC0%0/4
$name =~ /^\./ or defined $output and defined $abs and $abs eq $output
$name =~ /^\./
defined $output
defined $abs
$abs eq $output
Truth table0%0/5
A or B and C and D
A= $name =~ /^\./B= defined $outputC= defined $absD= $abs eq $output
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1049 | if $name =~ /^\./ or (defined $output and defined $abs and $abs eq $output); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1050 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1051 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1052 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1053 | 0 | ▶ | return if $name =~ /^\./; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1054 | 0 | my @stat = stat $path; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1055 | 0 | ▶ | $files{$path} = "$stat[9]:$stat[7]" if @stat; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1056 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1057 | 0 | }, '.'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1058 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1059 | 0 | return \%files; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1060 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1061 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1062 | 0 | ▶ | sub _same_snapshot { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_same_snapshot: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1063 | 0 | my ($old, $new) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1064 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1065 | 0 | ▶ | return 0 unless keys %$old == keys %$new; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1066 | 0 | for my $key (keys %$old) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1067 | 0 | ▶ | return 0 unless defined $new->{$key} and $new->{$key} eq $old->{$key}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $new->{$key} and $new->{$key} eq $old->{$key}
MC/DC0%0/2
defined $new->{$key} and $new->{$key} eq $old->{$key}
defined $new->{$key}
$new->{$key} eq $old->{$key}
Truth table0%0/3
A and B
A= defined $new->{$key}B= $new->{$key} eq $old->{$key}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1068 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1069 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1070 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1071 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1072 | # sub reset_site - Start a fresh site hash from the defaults. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1073 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1074 | 170 | ▶ | sub reset_site { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reset_site: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1075 | 170 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1076 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1077 | 170 | $self->{site} = App::Dapper::Defaults::get_defaults(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1078 | 170 | $self->{site}->{time} = App::Dapper::Utils::parse_date( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1079 | DateTime->now( time_zone => DateTime::TimeZone->new( name => 'local' ) )); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1080 | 6 | $self->{site}->{pages} = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1081 | 6 | $self->{site}->{categories} = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1082 | 6 | $self->{site}->{tags} = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1083 | 6 | $self->{layout_content} = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1084 | 6 | $self->{static_files} = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1085 | 6 | $self->{id} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1086 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1087 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1088 | # sub read_project - Read the project file and resolve the source, output and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1089 | # layout directories. Precedence: values passed to new() (the command line), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1090 | # then the project file, then the defaults. Pass a true value to allow the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1091 | # project file to be missing. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1092 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1093 | 3 | ▶ | sub read_project { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_project: called CC=11 SCAR=25.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1094 | 3 | my ($self, $optional) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1095 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1096 | 3 | $self->reset_site(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1097 | 3 | $self->{configured} = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1098 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1099 | 3 | ▶ | if (-f $self->{config}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1100 | 3 | my $config = eval { LoadFile($self->{config}) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1101 | 3 | ▶ | die "error: could not parse \"$self->{config}\": $@" if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1103 | 3 | ▶ | $config = {} unless defined $config; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1104 | 3 | ▶ | die "error: \"$self->{config}\" must contain key: value pairs\n" unless ref $config eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1106 | # Settings in the project file override the defaults | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1107 | 3 | @{$self->{site}}{keys %{$config}} = values %$config; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1108 | 3 | $self->{configured} = { map { $_ => 1 } keys %$config }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1109 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1110 | elsif (not $optional) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1111 | 0 | die "error: could not find the project file \"$self->{config}\". Run \"dapper init\" to create a new project.\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1113 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1114 | 3 | for my $key (qw/ source output layout /) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1115 | 9 | ▶ | my $value = $self->{explicit}->{$key} ? $self->{$key} : $self->{site}->{$key}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1116 | 9 | ▶ | die "error: \"$key\" must be defined in project file\n" unless defined $value and length $value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $value and length $value
MC/DC0%0/2
defined $value and length $value
defined $value
length $value
Truth table33%1/3
A and B
A= defined $valueB= length $value
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1117 | 9 | $value = canonpath($value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1118 | 9 | $self->{$key} = $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1119 | 9 | $self->{site}->{$key} = $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1120 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1121 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1122 | 3 | $self->{site}->{pages} = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1123 | 3 | $self->{site}->{categories} = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1124 | 3 | $self->{site}->{tags} = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1126 | 3 | $self->{data_dir} = canonpath($self->{site}->{data_dir}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1127 | 3 | ▶ | $self->{site}->{data} = -d $self->{data_dir} ? read_data($self->{data_dir}) : {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1128 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1129 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1130 | # sub read_data(dir) - Read every YAML (.yml, .yaml) and JSON (.json) file in a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1131 | # directory into a hash keyed by file name without the extension, so that | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1132 | # _data/authors.yml is available as site.data.authors. Directories become | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1133 | # nested hashes: _data/menus/main.yml is site.data.menus.main. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1135 | 0 | ▶ | sub read_data { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_data: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1136 | 0 | my ($dir) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1137 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1138 | 0 | my %data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1139 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1140 | 0 | my @entries = grep { !/^\./ } App::Dapper::Utils::read_dir($dir); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1141 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1142 | 0 | for my $entry (@entries) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1143 | 0 | my $path = "$dir/$entry"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1144 | 0 | ▶ | if (-d $path) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1145 | 0 | $data{$entry} = read_data($path); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1146 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1147 | elsif ($entry =~ /^(.+)\.(?:ya?ml)$/i) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1148 | 0 | my $value = eval { LoadFile($path) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1149 | 0 | ▶ | die "error: could not parse the data file \"$path\": $@" if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1150 | 0 | $data{$1} = $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1151 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1152 | elsif ($entry =~ /^(.+)\.json$/i) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1153 | 0 | my $value = eval { JSON->new->decode(App::Dapper::Utils::read_file($path)) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1154 | 0 | ▶ | die "error: could not parse the data file \"$path\": $@" if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1155 | 0 | $data{$1} = $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1156 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1157 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1158 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1159 | 0 | return \%data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1160 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1161 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1162 | # sub read_templates - Read the content of the layouts in the layout directory | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1163 | # and expand layouts that name a parent layout in their front matter. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1164 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1165 | 3 | ▶ | sub read_templates { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_templates: called CC=5 SCAR=16.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1166 | 3 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1167 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1168 | 3 | my %raw; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1169 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1170 | 3 | ▶ | die "error: could not open layout directory \"$self->{layout}\"\n" unless -d $self->{layout}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1171 | 3 | my @files = grep { !/^\./ } App::Dapper::Utils::read_dir($self->{layout}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1172 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1173 | 3 | for my $file (@files) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1174 | 3 | my $path = "$self->{layout}/$file"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1175 | 3 | ▶ | next unless -f $path; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1176 | 3 | $raw{App::Dapper::Utils::filter_stem($file)} = App::Dapper::Utils::read_file($path); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1177 | 3 | $self->{layout_file}->{App::Dapper::Utils::filter_stem($file)} = $path; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1178 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1179 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1180 | 3 | $self->{layout_content} = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1181 | 3 | for my $key (keys %raw) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1182 | 3 | $self->{layout_content}->{$key} = $self->expand_layout($key, \%raw, {}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1183 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1184 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1185 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1186 | # sub expand_layout - Return the content of a layout with its chain of parent | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1187 | # layouts applied, so that a layout may be wrapped by another layout, which | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1188 | # may in turn be wrapped by another. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1189 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1190 | 3 | ▶ | sub expand_layout { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
expand_layout: called CC=6 SCAR=28.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1191 | 3 | my ($self, $name, $raw, $seen) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1192 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1193 | 3 | ▶ | die "error: layout \"$name\" is part of a loop of layouts\n" if $seen->{$name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1194 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1195 | my ($frontmatter, $content) = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1196 | 3 | ▶ | App::Dapper::Utils::split_frontmatter($raw->{$name}, $self->{layout_file}->{$name} || "$self->{layout}/$name"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'layout_file'}{$name} || "$self->{'layout'}/$name"
MC/DC0%0/1
$self->{'layout_file'}{$name} || "$self->{'layout'}/$name"
$self->{'layout_file'}{$name}
Truth table50%1/2
A
A= $self->{'layout_file'}{$name}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1197 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1198 | 3 | ▶ | return $raw->{$name} unless defined $frontmatter; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1199 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1200 | 0 | my $parent = $frontmatter->{layout}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1201 | 0 | ▶ | return $content unless defined $parent; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1202 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1203 | 0 | ▶ | if (not exists $raw->{$parent}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1204 | 0 | warn "warning: layout \"$name\" names the layout \"$parent\", which does not exist\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1205 | 0 | return $content; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1206 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1207 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1208 | 0 | my $master = $self->expand_layout($parent, $raw, { %$seen, $name => 1 }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1209 | 0 | $master =~ s/\[%[-+=~]?\s*page\.content\s*[-+=~]?%\]/$content/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1210 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1211 | 0 | return $master; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1212 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1213 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1214 | # sub walk - Walk the source directory in sorted order, passing each file and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1215 | # its output path to build_inventory. Dot files and directories are skipped. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1216 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1217 | 3 | ▶ | sub walk { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
walk: called CC=7 SCAR=21.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1218 | 3 | my ($self, $source_dir, $output_dir, $schema) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1219 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1220 | 3 | ▶ | die "error: could not open source directory \"$source_dir\"\n" unless -d $source_dir; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1221 | 3 | my @entries = grep { !/^\./ } App::Dapper::Utils::read_dir($source_dir); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1222 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1223 | # A _schema.yml applies to this directory and those below it, unless they | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1224 | # have a schema of their own | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1225 | 3 | my $schema_file = "$source_dir/_schema.yml"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1226 | 3 | ▶ | if (-f $schema_file) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1227 | 0 | ▶ | $self->attempt($schema_file, sub { $schema = App::Dapper::Schema::load($schema_file) }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1228 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1229 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1230 | 3 | for my $entry (@entries) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1231 | 3 | ▶ | next if $entry eq '_schema.yml'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1232 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1233 | 3 | my $source = "$source_dir/$entry"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1234 | 3 | my $output = "$output_dir/$entry"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1235 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1236 | 3 | ▶ | if (-d $source) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1237 | 0 | $self->walk($source, $output, $schema); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1238 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1239 | elsif (-f $source) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1240 | 3 | ▶ | $self->attempt($source, sub { $self->build_inventory($source, $output, $schema) }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1241 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1242 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1243 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1244 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1245 | # sub build_inventory - Read one source file and add it to the site hash as a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1246 | # page, working out its date, slug, URL and output file. A file without front | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1247 | # matter is recorded to be copied as it is instead. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1248 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1249 | 3 | ▶ | sub build_inventory { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
build_inventory: called CC=54 SCAR=62.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1250 | 3 | my ($self, $source_file_name, $destination_file_name, $schema) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1251 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1252 | # Files without front matter (images, PDFs, etc.) are copied as they are | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1253 | 3 | ▶ | if (not App::Dapper::Utils::has_frontmatter($source_file_name)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1254 | 0 | push @{$self->{static_files}}, { source => $source_file_name, output => $destination_file_name }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1255 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1256 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1257 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1258 | 3 | $self->_log("Processing $source_file_name"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1259 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1260 | 3 | my $source_content = App::Dapper::Utils::read_file($source_file_name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1261 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1262 | 3 | my ($frontmatter, $content) = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1263 | App::Dapper::Utils::split_frontmatter($source_content, $source_file_name); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1264 | 3 | ▶ | die "error: \"$source_file_name\" has front matter that is never closed with a line containing ---\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1265 | unless defined $frontmatter; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1266 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1267 | # A page that does not match its schema is reported and goes no further | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1268 | 3 | ▶ | if ($schema) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1269 | 0 | my @messages = App::Dapper::Schema::validate($schema, $frontmatter); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1270 | 0 | for my $message (@messages) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1271 | 0 | ▶ | if ($self->{collect}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1272 | 0 | $self->problem('error', $source_file_name, "$message (see $schema->{file})"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1273 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1274 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1275 | 0 | push @{$self->{schema_errors}}, "$source_file_name: $message"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1276 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1277 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1278 | 0 | ▶ | return if @messages; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1279 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1280 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1281 | 3 | my %page = %$frontmatter; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1282 | 3 | $page{content} = $content; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1283 | 3 | $page{source} = $source_file_name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1284 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1285 | 0 | ▶ | my @categories = ref $page{categories} eq 'ARRAY' ? @{$page{categories}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1286 | : defined $page{categories} ? ($page{categories}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1287 | 3 | ▶ | : (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1288 | 0 | ▶ | @categories = grep { defined and !ref and length } @categories; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
defined $_ && !ref($_) && length $_
defined $_ and not ref $_
MC/DC0%0/3
defined $_ && !ref($_) && length $_
defined $_
not ref $_
length $_
Truth table0%0/4
A and not(B) && C
A= defined $_B= not ref $_C= length $_
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1289 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1290 | 3 | $page{slug} = App::Dapper::Utils::slugify($page{title}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1291 | 3 | ▶ | if (not defined $page{slug} or not length $page{slug}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $page{"slug"} and length $page{"slug"}
MC/DC0%0/2
defined $page{"slug"} and length $page{"slug"}
defined $page{"slug"}
length $page{"slug"}
Truth table33%1/3
A and B
A= defined $page{"slug"}B= length $page{"slug"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1292 | 0 | $page{slug} = App::Dapper::Utils::slugify(basename(App::Dapper::Utils::filter_stem($source_file_name))); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1293 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1294 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1295 | # A page without a date takes its file's modified time, which is a moment | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1296 | # (not a clock reading), so it keeps the local time zone it was read in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1297 | my $date = App::Dapper::Utils::parse_date( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1298 | defined $page{date} ? $page{date} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1299 | 3 | ▶ | : DateTime->from_epoch( epoch => (stat $source_file_name)[9], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1300 | time_zone => DateTime::TimeZone->new( name => 'local' ) ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1301 | $source_file_name); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1302 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1303 | # A date written without a time zone is in the page's time zone: its | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1304 | # "timezone" setting, the site's, or the local time zone | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1305 | 3 | ▶ | my $zone = $page{timezone} || $self->{site}->{timezone} || 'local'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition40%2/5
$page{'timezone'} || $self->{'site'}{'timezone'} || 'local'
$page{"timezone"} or $self->{"site"}{"timezone"}
MC/DC0%0/2
$page{'timezone'} || $self->{'site'}{'timezone'} || 'local'
$page{"timezone"}
$self->{"site"}{"timezone"}
Truth table33%1/3
A or B
A= $page{"timezone"}B= $self->{"site"}{"timezone"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1306 | my $timezone = Scalar::Util::blessed($zone) && $zone->isa('DateTime::TimeZone') ? $zone | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1307 | 3 | ▶ | : !ref $zone ? eval { DateTime::TimeZone->new( name => $zone ) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
builtin::blessed($zone) and $zone->isa("DateTime::TimeZone")
MC/DC0%0/2
builtin::blessed($zone) and $zone->isa("DateTime::TimeZone")
builtin::blessed($zone)
$zone->isa("DateTime::TimeZone")
Truth table33%1/3
A and B
A= builtin::blessed($zone)B= $zone->isa("DateTime::TimeZone")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1308 | : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1309 | 3 | ▶ | die "error: unknown time zone \"" . (ref $zone ? '(a list or map)' : $zone) . "\" in \"$source_file_name\"\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1310 | unless $timezone; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1311 | 3 | ▶ | $date->set_time_zone($timezone) if $date->time_zone->is_floating or not defined $page{date}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$date->time_zone->is_floating or not defined $page{"date"}
MC/DC0%0/2
$date->time_zone->is_floating or not defined $page{"date"}
$date->time_zone->is_floating
not defined $page{"date"}
Truth table33%1/3
A or not(B)
A= $date->time_zone->is_floatingB= not defined $page{"date"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1312 | 3 | $page{timezone} = $timezone; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1313 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1314 | # Drafts, and pages dated in the future, are held back unless drafts are | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1315 | # being shown (as "dapper serve" does) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1316 | 3 | ▶ | if (not $self->{drafts}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1317 | my $reason = App::Dapper::Publish::is_draft(\%page) ? 'draft' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1318 | : !($self->{site}->{future} && App::Dapper::Publish::enabled($self->{site}, 'future')) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1319 | 3 | ▶ | && DateTime->compare($date, $self->{site}->{time}) > 0 ? 'scheduled' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%2/6
not $self->{"site"}{"future"} && App::Dapper::Publish::enabled($self->{"site"}, "future") and "DateTime"->compare($date, $self->{"site"}{"time"}) > 0
$self->{'site'}{'future'} && App::Dapper::Publish::enabled($self->{'site'}, 'future')
MC/DC0%0/3
not $self->{"site"}{"future"} && App::Dapper::Publish::enabled($self->{"site"}, "future") and "DateTime"->compare($date, $self->{"site"}{"time"}) > 0
$self->{'site'}{'future'}
App::Dapper::Publish::enabled($self->{'site'}, 'future')
"DateTime"->compare($date, $self->{"site"}{"time"}) > 0
Truth table20%1/5
not(A && B) and C
A= $self->{'site'}{'future'}B= App::Dapper::Publish::enabled($self->{'site'}, 'future')C= "DateTime"->compare($date, $self->{"site"}{"time"}) > 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1320 | : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1321 | 3 | ▶ | if ($reason) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1322 | 0 | push @{$self->{held}}, { file => $source_file_name, reason => $reason, date => $date }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1323 | 0 | ▶ | $self->_log("Held back $source_file_name ($reason" . ($reason eq 'scheduled' ? " for $date" : '') . ")"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1324 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1325 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1326 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1327 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1328 | 3 | $page{date} = $date; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1329 | 3 | $page{year} = $date->year(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1330 | 3 | $page{month} = $date->month(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1331 | 3 | $page{day} = $date->day(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1332 | 3 | $page{hour} = $date->hour(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1333 | 3 | $page{minute} = $date->minute(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1334 | 3 | $page{second} = $date->second(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1335 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1336 | # Insert zero to beginning if year, month, day, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1337 | # hour, minute or second is less than 10 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1338 | $page{$_} < 10 and $page{$_} = '0' . $page{$_} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1339 | 3 | ▶ | for ('year', 'month', 'day', 'hour', 'minute', 'second'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1340 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1341 | 3 | $page{id} = ++$self->{id}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1342 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1343 | 3 | ▶ | if (not defined $page{extension}) { $page{extension} = $self->{site}->{extension}; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1344 | 3 | ▶ | $page{extension} = '' unless defined $page{extension}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1345 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1346 | 3 | $page{source_file_extension} = App::Dapper::Utils::filter_extension($source_file_name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1347 | 3 | ▶ | $page{source_file_extension} = '' unless defined $page{source_file_extension}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1348 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1349 | 3 | ▶ | if (@categories or defined $page{urlpattern}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@categories or defined $page{"urlpattern"}
MC/DC0%0/2
@categories or defined $page{"urlpattern"}
@categories
defined $page{"urlpattern"}
Truth table33%1/3
A or B
A= @categoriesB= defined $page{"urlpattern"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1350 | # The URL decides where the page is written | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1351 | 0 | ▶ | my $pattern = defined $page{urlpattern} ? $page{urlpattern} : $self->{site}->{urlpattern}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1352 | 0 | $page{url} = expand_urlpattern($pattern, { %page, category => $categories[0] }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1353 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1354 | 0 | my $filename = $page{url}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1355 | 0 | ▶ | $filename .= "index$page{extension}" if $filename =~ m{/$}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1356 | 0 | $page{filename} = canonpath(catfile($self->{output}, $filename)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1357 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1358 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1359 | # The path of the source file decides where the page is written | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1360 | 3 | $page{filename} = canonpath(App::Dapper::Utils::filter_stem($destination_file_name) . $page{extension}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1361 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1362 | 3 | my $url = File::Spec->abs2rel($page{filename}, $self->{output}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1363 | 3 | $url = join('/', File::Spec->splitdir($url)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1364 | 3 | ▶ | $url =~ s{(^|/)index\Q$page{extension}\E$}{$1} if length $page{extension}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1365 | 3 | $page{url} = "/$url"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1366 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1367 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1368 | 3 | my ($volume, $dirname, $file) = File::Spec->splitpath( $page{filename} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1369 | 3 | $page{dirname} = $dirname; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1370 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1371 | 3 | ▶ | if ($page{source_file_extension} eq ".md") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1372 | 3 | $page{markdown} = $page{content}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1373 | 3 | my @unknown; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1374 | $page{content} = App::Dapper::Markdown::to_html($page{content}, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1375 | layout => $self->{layout}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1376 | 3 | vars => { site => $self->{site}, page => \%page }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1377 | unknown => \@unknown, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1378 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1379 | 3 | my %seen; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1380 | 0 | for my $name (grep { !$seen{$_}++ } @unknown) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1381 | 0 | $self->problem('warning', $source_file_name, "$source_file_name uses the component \"::: $name\", which doesn't exist; the built-in ones are " | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1382 | . join(', ', App::Dapper::Components::names()) . ", and others can be added in $self->{layout}/components"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1383 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1384 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1385 | # Save first paragraph of content as excerpt | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1386 | 3 | ▶ | $page{excerpt} = $1 if $page{content} =~ /(<p>.*?<\/p>)/s; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1387 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1388 | ▶ | elsif ($page{source_file_extension} =~ /^\.html?$/i and $page{content} !~ /\[%/) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$page{"source_file_extension"} =~ /^\.html?$/i and not $page{"content"} =~ /\[%/
MC/DC0%0/2
$page{"source_file_extension"} =~ /^\.html?$/i and not $page{"content"} =~ /\[%/
$page{"source_file_extension"} =~ /^\.html?$/i
not $page{"content"} =~ /\[%/
Truth table0%0/3
A and not(B)
A= $page{"source_file_extension"} =~ /^\.html?$/iB= not $page{"content"} =~ /\[%/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1389 | # An HTML page's first paragraph too (an imported post, say), unless | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1390 | # it holds template code, which hasn't run yet | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1391 | 0 | ▶ | $page{excerpt} = $1 if $page{content} =~ /(<p\b[^>]*>.*?<\/p>)/is; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1392 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1393 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1394 | # Remove leading spaces and newline | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1395 | 3 | $page{content} =~ s/^[ \n]*//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1396 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1397 | 3 | for my $category (@categories) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1398 | 0 | ▶ | my $list = $self->{site}->{categories}->{$category} ||= []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"site"}{"categories"}{$category} ||= []
MC/DC0%0/1
$self->{"site"}{"categories"}{$category} ||= []
$self->{"site"}{"categories"}{$category}
Truth table0%0/2
A
A= $self->{"site"}{"categories"}{$category}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1399 | 0 | push @$list, \%page; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1400 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1401 | # Keep the array sorted | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1402 | 0 | @$list = sort { $a->{date} <=> $b->{date} } @$list; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1403 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1404 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1405 | 0 | ▶ | my @tags = ref $page{tags} eq 'ARRAY' ? @{$page{tags}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1406 | : defined $page{tags} ? ($page{tags}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1407 | 3 | ▶ | : (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1408 | 0 | ▶ | for my $tag (grep { defined and !ref and length } @tags) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
defined $_ && !ref($_) && length $_
defined $_ and not ref $_
MC/DC0%0/3
defined $_ && !ref($_) && length $_
defined $_
not ref $_
length $_
Truth table0%0/4
A and not(B) && C
A= defined $_B= not ref $_C= length $_
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1409 | 0 | ▶ | my $list = $self->{site}->{tags}->{$tag} ||= []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"site"}{"tags"}{$tag} ||= []
MC/DC0%0/1
$self->{"site"}{"tags"}{$tag} ||= []
$self->{"site"}{"tags"}{$tag}
Truth table0%0/2
A
A= $self->{"site"}{"tags"}{$tag}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1410 | 0 | push @$list, \%page; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1411 | 0 | @$list = sort { $a->{date} <=> $b->{date} } @$list; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1412 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1413 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1414 | 3 | push @{$self->{site}->{pages}}, \%page; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1415 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1416 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1417 | =head2 expand_urlpattern | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1418 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1419 | Takes a URL pattern (e.g. C</:category/:year/:month/:slug/>) and a hash of page | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1420 | values, and returns the URL with each C<:name> token replaced. The tokens are | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1421 | C<:category>, C<:tag>, C<:year>, C<:month>, C<:day>, C<:hour>, C<:minute>, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1422 | C<:second> and C<:slug>. Tokens with no | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1423 | value are removed along with their slash. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1424 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1425 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1426 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1427 | 24 | ▶ | sub expand_urlpattern { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
expand_urlpattern: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1428 | 24 | my ($pattern, $page) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1429 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1430 | 24 | ▶ | my $url = defined $pattern ? $pattern : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1431 | 24 | for my $token (qw/ category tag year month day hour minute second slug /) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1432 | 216 | my $value = $page->{$token}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1433 | 216 | ▶ | $value = '' unless defined $value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1434 | 216 | $url =~ s/:$token\b/$value/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1435 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1436 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1437 | 24 | $url =~ s{/{2,}}{/}g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1438 | 24 | ▶ | $url = "/$url" unless $url =~ m{^/}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1439 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1440 | 24 | return $url; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1441 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1442 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1443 | # sub copy(sourcedir, outputdir) - Copy the files and directories in <sourcedir> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1444 | # to <outputdir>, except those whose names match a pattern in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1445 | # $self->{site}->{ignore}. The source, output and layout directories and the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1446 | # project file are never copied. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1447 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1448 | 3 | ▶ | sub copy { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
copy: called CC=14 SCAR=44.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1449 | 3 | my ($self, $dir, $output) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1450 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1451 | 12 | my @skip = map { abs_path($_) } grep { -e $_ } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1452 | 3 | ($self->{source}, $self->{output}, $self->{layout}, $self->{config}, $self->{data_dir}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1453 | 3 | my %skip = map { $_ => 1 } grep { defined } @skip; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1454 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1455 | 3 | ENTRY: for my $file (App::Dapper::Utils::read_dir($dir)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1456 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1457 | 12 | ▶ | for my $i (@{ $self->{site}->{ignore} || [] }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'site'}{'ignore'} || []
MC/DC0%0/1
$self->{'site'}{'ignore'} || []
$self->{'site'}{'ignore'}
Truth table50%1/2
A
A= $self->{'site'}{'ignore'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1458 | 24 | ▶ | next ENTRY if ($file =~ m/$i/); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1459 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1460 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1461 | # The notes for AI coding agents are for the project, not the site | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1462 | 0 | ▶ | next if $dir eq '.' and $file =~ /^(?:AGENTS|CLAUDE)\.md$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$dir eq "." and $file =~ /^(?:AGENTS|CLAUDE)\.md$/
MC/DC0%0/2
$dir eq "." and $file =~ /^(?:AGENTS|CLAUDE)\.md$/
$dir eq "."
$file =~ /^(?:AGENTS|CLAUDE)\.md$/
Truth table0%0/3
A and B
A= $dir eq "."B= $file =~ /^(?:AGENTS|CLAUDE)\.md$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1463 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1464 | 0 | ▶ | my $path = $dir eq '.' ? $file : "$dir/$file"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1465 | 0 | my $abs = abs_path($path); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1466 | 0 | ▶ | next if defined $abs and $skip{$abs}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $abs and $skip{$abs}
MC/DC0%0/2
defined $abs and $skip{$abs}
defined $abs
$skip{$abs}
Truth table0%0/3
A and B
A= defined $absB= $skip{$abs}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1467 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1468 | # A symbolic link to nothing can't be copied | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1469 | 0 | ▶ | if (-l $path and not -e $path) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-l $path and not -e $path
MC/DC0%0/2
-l $path and not -e $path
-l $path
not -e $path
Truth table0%0/3
A and not(B)
A= -l $pathB= not -e $path
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1470 | 0 | $self->problem('warning', $path, "$path is a symbolic link to something that doesn't exist, so it was not copied"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1471 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1472 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1473 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1474 | 0 | my $target = canonpath(catfile($output, $file)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1475 | 0 | ▶ | if (-f $path and defined(my $owner = $self->{page_owner}->{$target})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-f $path and defined(my $owner = $self->{"page_owner"}{$target})
MC/DC0%0/2
-f $path and defined(my $owner = $self->{"page_owner"}{$target})
-f $path
defined(my $owner = $self->{"page_owner"}{$target})
Truth table0%0/3
A and B
A= -f $pathB= defined(my $owner = $self->{"page_owner"}{$target})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1476 | 0 | $self->problem('error', $path, "$path and $owner both write $target"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1477 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1478 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1479 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1480 | 0 | $self->record_written(App::Dapper::Utils::copy_recursive($path, catfile($output, $file), $self->{output})); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1481 | 0 | $self->_log("Copied $path"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1482 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1483 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1484 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1485 | # sub _log - Print a progress message unless quiet. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1486 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1487 | 18 | ▶ | sub _log { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_log: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1488 | 18 | my ($self, $message) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1489 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1490 | 18 | ▶ | print "$message\n" unless $self->{quiet}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1491 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1492 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1493 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1494 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1495 | Mark Benson, C<< <mark at jayber.org> >> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1496 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1497 | =head1 BUGS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1498 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1499 | Please report any bugs or feature requests at | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1500 | L<https://github.com/markdbenson/dapper/issues>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1501 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1502 | =head1 SUPPORT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1503 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1504 | You can find documentation for this module with the perldoc command. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1505 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1506 | perldoc App::Dapper | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1507 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1508 | You can also look for information at: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1509 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1510 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1511 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1512 | =item * GitHub: source code and issue tracker | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1513 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1514 | L<https://github.com/markdbenson/dapper> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1515 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1516 | =item * MetaCPAN | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1517 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1518 | L<https://metacpan.org/dist/App-Dapper> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1519 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1520 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1521 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1522 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1523 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1524 | The MIT License (MIT) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1525 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1526 | Copyright (c) 2002-2026 Mark Benson | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1527 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1528 | Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1529 | of this software and associated documentation files (the "Software"), to deal | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1530 | in the Software without restriction, including without limitation the rights | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1531 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1532 | copies of the Software, and to permit persons to whom the Software is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1533 | furnished to do so, subject to the following conditions: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1534 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1535 | The above copyright notice and this permission notice shall be included in all | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1536 | copies or substantial portions of the Software. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1537 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1538 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1539 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1540 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1541 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1542 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1543 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1544 | SOFTWARE. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1545 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1546 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1547 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1548 | 190 | 1; # End of App::Dapper | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||