Skip to content

Commit d9cf8d3

Browse files
committed
add build_date to site, set during build
Before this commit any functionality that depended on knowing the build date (which is possibly overridden by the command line) would need to have the date passed in to it. With this change the site now knows what the build date is and is therefore accessible by anything with access to the site object.
1 parent 7319ebf commit d9cf8d3

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

lib/Statocles/App/Blog.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ Defaults to the current date.
465465
# sub pages
466466
around pages => sub {
467467
my ( $orig, $self, %opt ) = @_;
468-
$opt{date} ||= DateTime::Moonpig->now( time_zone => 'local' )->ymd;
468+
$opt{date} ||= $self->site->build_date;
469469
my $root = $self->url_root;
470470
my $is_dated_path = qr{^$root/?(\d{4})/(\d{2})/(\d{2})/};
471471
my @parent_pages = $self->$orig( %opt );

lib/Statocles/Command/build.pm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ sub run {
1212
'base_url|base=s',
1313
);
1414

15+
if ($build_opt{date}) {
16+
$self->site->build_date($build_opt{date});
17+
}
18+
1519
my $path = Path::Tiny->new( $argv[0] // '.statocles/build' );
1620
$path->mkpath;
1721

lib/Statocles/Command/daemon.pm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ sub run {
1515
'date|d=s',
1616
);
1717

18+
if ($build_opt{date}) {
19+
$self->site->build_date($build_opt{date});
20+
}
21+
1822
require Mojo::Server::Daemon;
1923
my $app = Statocles::Command::daemon::_MOJOAPP->new(
2024
site => $self->site,

lib/Statocles/Site.pm

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use Mojo::Log;
1010
use Statocles::Page::Plain;
1111
use Statocles::Util qw( derp );
1212
use List::UtilsBy qw( uniq_by );
13+
use DateTime::Moonpig;
1314

1415
=attr title
1516
@@ -397,6 +398,27 @@ has _pages => (
397398
clearer => 'clear_pages',
398399
);
399400

401+
=attr build_date
402+
403+
---
404+
build_date: 2015-03-27
405+
build_date: 2015-03-27 12:04:00
406+
---
407+
408+
The date/time of the current build of the site. This is usually set by a build
409+
(or related) command. Defaults to the current date.
410+
411+
Should be in C<YYYY-MM-DD> or C<YYYY-MM-DD HH:MM:SS> format.
412+
413+
=cut
414+
415+
has build_date => (
416+
is => 'rw',
417+
isa => DateTimeObj,
418+
coerce => DateTimeObj->coercion,
419+
default => sub { DateTime::Moonpig->now( time_zone => 'local' )->ymd },
420+
);
421+
400422
=method BUILD
401423
402424
Register this site as the global site.

0 commit comments

Comments
 (0)