diff --git a/src/Generator.php b/src/Generator.php index 00c29fc..9c96f3a 100644 --- a/src/Generator.php +++ b/src/Generator.php @@ -2,7 +2,9 @@ namespace Statamic\StaticSite; +use Carbon\Carbon; use Spatie\Fork\Fork; +use Statamic\Statamic; use Facades\Statamic\View\Cascade; use Statamic\Facades\URL; use Statamic\Support\Str; @@ -258,6 +260,13 @@ protected function makeContentGenerationClosures($pages, $request) $errors = []; foreach ($pages as $page) { + // There is no getter method, so use reflection. + $oldCarbonFormat = (new \ReflectionClass(Carbon::class))->getStaticPropertyValue('toStringFormat'); + + if ($this->shouldSetCarbonFormat($page)) { + Carbon::setToStringFormat(Statamic::dateFormat()); + } + $this->updateCurrentSite($page->site()); view()->getFinder()->setPaths($this->viewPaths); @@ -277,6 +286,8 @@ protected function makeContentGenerationClosures($pages, $request) $errors[] = $e->consoleMessage(); continue; + } finally { + Carbon::setToStringFormat($oldCarbonFormat); } if ($generated->hasWarning()) { @@ -385,7 +396,7 @@ protected function routes() && ! Str::contains($route->uri(), '{'); })->map(function ($route) { $url = URL::tidy(Str::start($route->uri(), $this->config['base_url'].'/')); - return $this->createPage(new Route($url)); + return $this->createPage(new StatamicRoute($url)); }); } @@ -424,4 +435,13 @@ protected function shouldFail($item) return $config === 'warnings'; } + + protected function shouldSetCarbonFormat($page) + { + $content = $page->content(); + + return $content instanceof \Statamic\Contracts\Entries\Entry + || $content instanceof \Statamic\Contracts\Taxonomies\Term + || $content instanceof StatamicRoute; + } } diff --git a/src/Page.php b/src/Page.php index ebfc8ae..b0f5ba9 100644 --- a/src/Page.php +++ b/src/Page.php @@ -20,6 +20,11 @@ public function __construct(Filesystem $files, array $config, $content) $this->content = $content; } + public function content() + { + return $this->content; + } + public function isGeneratable() { return $this->content->published(); diff --git a/src/StatamicRoute.php b/src/StatamicRoute.php new file mode 100644 index 0000000..97a1579 --- /dev/null +++ b/src/StatamicRoute.php @@ -0,0 +1,8 @@ +