Given /blog/mark-keating/blah load blog.css, blog/mark-keating.css etc
[scpubgit/App-SCS.git] / lib / App / SCS / Plugin / Core / PagePlugin / PageData.pm
index d84bc54..42910de 100644 (file)
@@ -30,18 +30,38 @@ sub filter_content_zoom {
        ->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('');
+           my $path = '';
+           my $replace = '';
+           my @parts = split /\//, $page->path;
+
+           foreach my $part (@parts) {
+               next unless $part;
+
+               $path .= "/" . $part;
+
+               if (-f $static_dir . "/page-css/$path.css") {
+                   $replace .= "<link href='/static/page-css/$path.css' rel='stylesheet' type='text/css' />";
+               }
            }
+
+           $_[0]->replace(HTML::Zoom->from_html($replace));
          }}
        ->select('script[data-cur-page-js]')->${\sub {
-          if (-f $static_dir . "/page-js/" . $page->path . ".js") {
-              $_[0]->set_attribute(src => "/static/page-js/" . $page->path . ".js");
-          } else {
-              $_[0]->replace('');
-          }
+           my $path = '';
+           my $replace = '';
+           my @parts = split /\//, $page->path;
+
+           foreach my $part (@parts) {
+               next unless $part;
+
+               $path .= "/" . $part;
+
+               if (-f $static_dir . "/page-js/$path.js") {
+                   $replace .= "<script src='/static/page-js/$path.js' type='text/javascript'></script>";
+               }
+           }
+
+           $_[0]->replace(HTML::Zoom->from_html($replace));
          }}
 }