package App::SCS::Plugin::Core::PagePlugin::PageData;

use Moo;

with 'App::SCS::Role::PagePlugin';

has static_dir => (is => 'ro', required => 1);

sub filter_content_zoom {
  my ($self, $zoom) = @_;

  my $page = $self->page;
  my $static_dir = $self->static_dir;

  $zoom->select('.page.title')->replace_content($page->title)
       ->select('.page.subtitle')->${\sub {
           $page->subtitle
             ? $_[0]->replace_content($page->subtitle)
             : $_[0]->replace('')
         }}
       ->select('.page.published_at')->${\sub {
           $page->published_at
           ? $_[0]->replace_content($page->published_at)
           : $_[0]->replace('')
         }}
       ->select('meta[name=description]')
         ->set_attribute(content => $page->description)
       ->select('meta[name=keywords]')
         ->set_attribute(content => $page->keywords)
       ->select('meta[name=created]')
         ->set_attribute(content => $page->created)
       ->select('link[data-cur-page-css]')->${\sub {
           if (-f $static_dir . "/page-css/" . $page->path . ".css") {
               $_[0]->set_attribute(href => "/static/page-css/" . $page->path . ".css");
           } else {
               $_[0]->replace('');
           }
         }}
}

1;
