|
|
@@ -33,6 +33,7 @@ use Trog::Config;
|
|
|
use Trog::Auth;
|
|
|
use Trog::Data;
|
|
|
use Trog::Themes;
|
|
|
+use Trog::Bundle;
|
|
|
use Trog::Renderer;
|
|
|
use Trog::Email;
|
|
|
use Trog::DataSource;
|
|
|
@@ -295,6 +296,10 @@ our %routes = (
|
|
|
method => 'GET',
|
|
|
callback => \&Trog::Routes::HTML::rss_style,
|
|
|
},
|
|
|
+ '/bundle/{version}/{names}.js' => {
|
|
|
+ method => 'GET',
|
|
|
+ callback => \&Trog::Routes::HTML::bundle,
|
|
|
+ },
|
|
|
);
|
|
|
|
|
|
# Grab theme routes
|
|
|
@@ -838,7 +843,6 @@ sub config ( $query = {} ) {
|
|
|
title => 'Configure tCMS',
|
|
|
theme_dir => Trog::Themes::td(),
|
|
|
stylesheets => [qw{config.css}],
|
|
|
- scripts => [qw{post.js}],
|
|
|
themes => get_themes() || [],
|
|
|
config_sections => config_sections(),
|
|
|
message => $query->{message},
|
|
|
@@ -1043,7 +1047,6 @@ sub resetpass ($query) {
|
|
|
title => 'Request Authentication Resets',
|
|
|
theme_dir => Trog::Themes::td(),
|
|
|
stylesheets => [qw{config.css}],
|
|
|
- scripts => [qw{post.js}],
|
|
|
message => $query->{message},
|
|
|
failure => $query->{failure},
|
|
|
scheme => $query->{scheme},
|
|
|
@@ -1883,7 +1886,8 @@ sub posts ( $query, $direct = 0 ) {
|
|
|
return $content if ref $content eq "ARRAY";
|
|
|
|
|
|
return $content if $direct;
|
|
|
- return Trog::Routes::HTML::index( $query, $content, $styles );
|
|
|
+ my @scripts = ( ( $is_admin ? qw{post.js post_relations.js} : () ), qw{highlight.min.js reveal.min.js} );
|
|
|
+ return Trog::Routes::HTML::index( $query, $content, $styles, \@scripts );
|
|
|
}
|
|
|
|
|
|
=head2 redact_private($post, $seen)
|
|
|
@@ -2350,7 +2354,7 @@ sub metrics ($query) {
|
|
|
},
|
|
|
undef,
|
|
|
['post.css'],
|
|
|
- ['chart.js'],
|
|
|
+ ['chart.min.js'],
|
|
|
);
|
|
|
}
|
|
|
|
|
|
@@ -2667,6 +2671,7 @@ sub post_wizard ($query) {
|
|
|
},
|
|
|
undef,
|
|
|
['post.css'],
|
|
|
+ ['post_wizard.js'],
|
|
|
);
|
|
|
}
|
|
|
|
|
|
@@ -3379,6 +3384,31 @@ sub icon ($query) {
|
|
|
return $query->{tpsgi}->serve( $path, $tpath, $query->{start}, $query->{streaming}, $query->{ranges}, $query->{last_fetched}, $query->{deflate} );
|
|
|
}
|
|
|
|
|
|
+=head2 bundle
|
|
|
+
|
|
|
+Implements /bundle/{version}/{names}.js, the scripts of a page as one response.
|
|
|
+See Trog::Bundle.
|
|
|
+
|
|
|
+The body of a bundle is the same at a given href, so the browser keeps it. An
|
|
|
+href with an old version is redirected to the current one, so a page that was
|
|
|
+cached before a script changed still gets its scripts.
|
|
|
+
|
|
|
+=cut
|
|
|
+
|
|
|
+sub bundle ($query) {
|
|
|
+ my $bundle = Trog::Bundle::scripts( map { "$_.js" } split( /[+]/, $query->{names} ) );
|
|
|
+ return $query->{tpsgi}->notfound($query) unless $bundle;
|
|
|
+ return $query->{tpsgi}->redirect( $bundle->{href} ) if $query->{route} ne $bundle->{href};
|
|
|
+ return [
|
|
|
+ 200,
|
|
|
+ [
|
|
|
+ 'Content-type' => 'text/javascript',
|
|
|
+ 'Cache-Control' => $Trog::Vars::cache_control{static},
|
|
|
+ ],
|
|
|
+ [ $bundle->{body} ],
|
|
|
+ ];
|
|
|
+}
|
|
|
+
|
|
|
=head2 totp_qr
|
|
|
|
|
|
Implements the /totp/* routes.
|
|
|
@@ -3459,15 +3489,15 @@ sub finish_render ( $template, $vars, %headers ) {
|
|
|
# Theme-ize the paths
|
|
|
$vars->{stylesheets} = [ @{ build_themed_styles( $vars->{stylesheets} ) } ];
|
|
|
$vars->{print_styles} = [ @{ build_themed_styles( $vars->{print_styles} ) } ];
|
|
|
- $vars->{scripts} = [ map { Trog::Themes::themed_script("$_") =~ s/^www\///r } @{ Trog::Utils::coerce_array( $vars->{scripts} ) } ];
|
|
|
+ my $bundle = Trog::Bundle::scripts( @{ Trog::Utils::coerce_array( $vars->{scripts} ) } );
|
|
|
+ $vars->{scripts} = $bundle ? [ $bundle->{href} ] : [];
|
|
|
|
|
|
# Add in avatars.css, it's special
|
|
|
push( @{ $vars->{stylesheets} }, "/styles/avatars.css" );
|
|
|
|
|
|
- # Absolute-ize the paths for scripts & stylesheets
|
|
|
+ # Absolute-ize the paths for stylesheets
|
|
|
@{ $vars->{stylesheets} } = map { CORE::index( $_, '/' ) == 0 ? $_ : "/$_" } @{ $vars->{stylesheets} };
|
|
|
@{ $vars->{print_styles} } = map { CORE::index( $_, '/' ) == 0 ? $_ : "/$_" } @{ $vars->{print_styles} };
|
|
|
- @{ $vars->{scripts} } = map { CORE::index( $_, '/' ) == 0 ? $_ : "/$_" } @{ $vars->{scripts} };
|
|
|
|
|
|
# TODO Smash together the stylesheets and minify
|
|
|
|