Custom HTML elements for blog authors
[scpubgit/App-SCS.git] / lib / App / SCS / Plugin / Core / PagePlugin / PageData.pm
CommitLineData
632f0e07 1package App::SCS::Plugin::Core::PagePlugin::PageData;
2
3use Moo;
4
5with 'App::SCS::Role::PagePlugin';
6
0023adab 7has static_dir => (is => 'ro', required => 1);
8
632f0e07 9sub filter_content_zoom {
10 my ($self, $zoom) = @_;
0023adab 11
632f0e07 12 my $page = $self->page;
0023adab 13 my $static_dir = $self->static_dir;
14
632f0e07 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 }}
d347b8dd 21 ->select('.page.published_at')->${\sub {
22 $page->published_at
23 ? $_[0]->replace_content($page->published_at)
24 : $_[0]->replace('')
25 }}
632f0e07 26 ->select('meta[name=description]')
27 ->set_attribute(content => $page->description)
28 ->select('meta[name=keywords]')
29 ->set_attribute(content => $page->keywords)
30 ->select('meta[name=created]')
0023adab 31 ->set_attribute(content => $page->created)
32 ->select('link[data-cur-page-css]')->${\sub {
b16f44d3 33 my $path = '';
34 my $replace = '';
35 my @parts = split /\//, $page->path;
36
37 foreach my $part (@parts) {
38 next unless $part;
39
40 $path .= "/" . $part;
41
42 if (-f $static_dir . "/page-css/$path.css") {
43 $replace .= "<link href='/static/page-css/$path.css' rel='stylesheet' type='text/css' />";
44 }
0023adab 45 }
b16f44d3 46
47 $_[0]->replace(HTML::Zoom->from_html($replace));
0023adab 48 }}
35af866e 49 ->select('script[data-cur-page-js]')->${\sub {
b16f44d3 50 my $path = '';
51 my $replace = '';
52 my @parts = split /\//, $page->path;
53
54 foreach my $part (@parts) {
55 next unless $part;
56
57 $path .= "/" . $part;
58
59 if (-f $static_dir . "/page-js/$path.js") {
60 $replace .= "<script src='/static/page-js/$path.js' type='text/javascript'></script>";
61 }
62 }
63
64 $_[0]->replace(HTML::Zoom->from_html($replace));
35af866e 65 }}
3eae042f 66 ->select('div[data-custom-blog-elements]')->${\sub {
67 #blog/author(/post)
68
69 return $_[0]->replace('') if $page->path !~ qr#^/blog/([^/]+)/+#;
70
71 my $author = $1;
72 my $author_templ = $static_dir . "/author-html/$author.html";
73
74 if (-f $author_templ) {
75 $_[0]->replace(HTML::Zoom->from_file($author_templ));
76 } else {
77 $_[0]->replace('');
78 }
79 }}
632f0e07 80}
81
821;