a35d2f44d5162d0f05ca612d7c216119f1d7f6ff
[scpubgit/App-SCS.git] / lib / App / SCS / Plugin / Core / PagePlugin / PageData.pm
1 package App::SCS::Plugin::Core::PagePlugin::PageData;
2
3 use Moo;
4
5 with 'App::SCS::Role::PagePlugin';
6
7 has static_dir => (is => 'ro', required => 1);
8
9 sub filter_content_zoom {
10   my ($self, $zoom) = @_;
11
12   my $page = $self->page;
13   my $static_dir = $self->static_dir;
14
15   $zoom->select('.page.title')->replace_content($page->title)
16        ->select('.page.subtitle')->${\sub {
17            $page->subtitle
18              ? $_[0]->replace_content($page->subtitle)
19              : $_[0]->replace('')
20          }}
21        ->select('.page.published_at')->replace_content($page->published_at)
22        ->select('meta[name=description]')
23          ->set_attribute(content => $page->description)
24        ->select('meta[name=keywords]')
25          ->set_attribute(content => $page->keywords)
26        ->select('meta[name=created]')
27          ->set_attribute(content => $page->created)
28        ->select('link[data-cur-page-css]')->${\sub {
29            if (-f $static_dir . "/page-css/" . $page->path . ".css") {
30                $_[0]->set_attribute(href => "/static/page-css/" . $page->path . ".css");
31            } else {
32                $_[0]->replace('');
33            }
34          }}
35 }
36
37 1;