]> bicyclesonthemoon.info Git - ott/bsta/commitdiff
preload previous page / frame
authorb <rowerynaksiezycu@gmail.com>
Thu, 11 Jan 2024 14:48:54 +0000 (14:48 +0000)
committerb <rowerynaksiezycu@gmail.com>
Thu, 11 Jan 2024 14:48:54 +0000 (14:48 +0000)
bsta_lib.1.pm
viewer.1.pl

index b5301f05027c01a692a0afe4c18009f406a4f47d..fc713655d741193ca947b488d2d3dc7e593ff99a 100644 (file)
@@ -859,6 +859,7 @@ sub print_viewer_page {
                my $state,
                my $settings,
                my $frame_data,
+               my $prev_frame_data,
                my $next_frame_data,
                my $words_data,
        ) = @_;
@@ -875,7 +876,7 @@ sub print_viewer_page {
        my $timer          = int($context->{'timer'});
        # my $words_page     = int($context->{'words_page'});
        
-       my $prev_frame = $frame - 1;
+       my $prev_frame = $frame - 1;
        my $next_frame = $frame + 1;
        
        my $story = $settings->{'story'};
@@ -923,6 +924,13 @@ sub print_viewer_page {
        
        my $prev_available = (($frame > 0) && $access);
        my $next_available = ($launch || $password_ok || ($next_frame <= $last_frame));
+       my $prefetch_prev = (
+               $password_ok ||
+               ($prev_frame < $last_frame) || (  # avoid unseen trigger!
+                       ($prev_frame <= $last_frame) &&
+                       ($ong_state >= STATE->{'ready'})
+               )
+       );
        my $prefetch_next  = (
                $password_ok ||
                ($next_frame < $last_frame) || (  # avoid unseen trigger!
@@ -959,6 +967,7 @@ sub print_viewer_page {
                        ($ong_state > STATE->{'inactive'})
                )
        );
+       my $prevframe_indirect = !($prev_frame <= $last_frame);
        my $nextframe_indirect = !($next_frame <= $last_frame);
        
        my $password_query;
@@ -981,7 +990,7 @@ sub print_viewer_page {
        );
        my $viewer_prev_url = merge_url(
                {'path' => CGI_VIEWER_PATH()},
-               {'path' => $frame-1}
+               {'path' => $prev_frame}
        );
        my $viewer_next_url = merge_url(
                {'path' => CGI_VIEWER_PATH()},
@@ -1030,6 +1039,7 @@ sub print_viewer_page {
        );
        my $frame_file;
        my $frame_url;
+       my $frame_prev_url;
        my $frame_next_url;
        my $frame_normal_url;
        my $frame_full_url;
@@ -1056,6 +1066,23 @@ sub print_viewer_page {
                {'scheme' => SCHEME(), 'host' => WEBSITE()},
                {'path' => $frame_normal_url}
        );
+       if ($prevframe_indirect) {
+               $frame_prev_url = merge_url(
+                       {'path' => CGI_FRAME_PATH()},
+                       {'path' => $prev_frame}
+               );
+       }
+       elsif ($prev_frame_data->{'frame'} ne '') {
+               $frame_prev_url = merge_url(
+                       {'path' => CGI_PATH()},
+                       {'path' => $prev_frame_data->{'frame'}}
+               );
+       }
+       else {
+               $frame_prev_url = merge_url(CGI_PATH(), sprintf(
+                       $settings->{'frame'}, $prev_frame, $prev_frame_data->{'ext'}
+               ));
+       }
        if ($nextframe_indirect) {
                $frame_next_url = merge_url(
                        {'path' => CGI_FRAME_PATH()},
@@ -1088,6 +1115,9 @@ sub print_viewer_page {
                if ($frame_indirect) {
                        $frame_url     = merge_url($frame_url      , {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
                }
+               if ($prevframe_indirect) {
+                       $frame_prev_url= merge_url($frame_prev_url , {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
+               }
                if ($nextframe_indirect) {
                        $frame_next_url= merge_url($frame_next_url , {'query' => $password_query, 'append_query' => 1, 'preserve_fragment' => 1});
                }
@@ -1105,6 +1135,7 @@ sub print_viewer_page {
        my $_viewer_next_url = html_entity_encode_dec($viewer_next_url, 1);
        my $_viewer_last_url = html_entity_encode_dec($viewer_last_url, 1);
        my $_frame_url       = html_entity_encode_dec($frame_url      , 1);
+       my $_frame_prev_url  = html_entity_encode_dec($frame_prev_url , 1);
        my $_frame_next_url  = html_entity_encode_dec($frame_next_url , 1);
        my $_frame_full_url  = html_entity_encode_dec($frame_full_url , 1);
        
@@ -1150,6 +1181,10 @@ sub print_viewer_page {
        print $fh '  <link rel="start" href="'.$_viewer_0_url.'">'."\n";
        if ($prev_available) {
                print $fh '  <link rel="prev" href="'.$_viewer_prev_url.'">'."\n";
+               if ($prefetch_prev) {
+                       print $fh '  <link rel="prefetch" href="'.$_viewer_prev_url.'">'."\n";
+                       print $fh '  <link rel="prefetch" href="'.$_frame_prev_url.'">'."\n";
+               }
        }
        if ($next_available) {
                print $fh '  <link rel="next" href="'.$_viewer_next_url.'">'."\n";
@@ -1537,6 +1572,7 @@ sub write_index {
                        $state,
                        $settings,
                        \%frame_data,
+                       \%default, # prev
                        \%next_frame_data,
                        \%words_data
                );
@@ -1619,6 +1655,7 @@ sub write_index {
                                $state,
                                $settings,
                                \%frame_data,
+                               \%default, # prev
                                \%next_frame_data,
                                {'posts' => 0} # words_data
                        );
index 24a72b49812853599d9dfda7ef0b8a2341224f42..84a26bfb016434960ce793eb6f712a48dc48f78c 100644 (file)
@@ -63,6 +63,7 @@ srand ($time-$$);
 my %http;
 my %cgi;
 my %frame_data;
+my %prev_frame_data;
 my %next_frame_data;
 my %default;
 my %settings;
@@ -74,6 +75,7 @@ my %words_data;
 my $method;
 my $frame;
 my $frame_data_path;
+my $prev_frame_data_path;
 my $next_frame_data_path;
 my $password;
 my $password_ok;
@@ -231,13 +233,6 @@ else {
        $state{'state'} = STATE->{'inactive'};
 }
 
-$next_frame_data_path = join_path(PATH_SEPARATOR(), DATA_PATH(), $frame+1);
-%next_frame_data = read_data_file($next_frame_data_path);
-
-# apply defaults
-%frame_data      = merge_settings(\%default,      \%frame_data);
-%next_frame_data = merge_settings(\%default, \%next_frame_data);
-
 $timer   = int($state{'nextong'}) - $time;
 $ongtime = int($state{'ongtime'});
 if($ongtime == 0) {
@@ -269,6 +264,16 @@ if (
                )
        ) {
        $access = 1;
+       if ($frame > 0) {
+               $prev_frame_data_path = join_path(PATH_SEPARATOR(), DATA_PATH(), $frame-1);
+               %prev_frame_data = read_data_file($prev_frame_data_path);
+       }
+       $next_frame_data_path = join_path(PATH_SEPARATOR(), DATA_PATH(), $frame+1);
+       %next_frame_data = read_data_file($next_frame_data_path);
+       
+       %frame_data      = merge_settings(\%default,      \%frame_data);
+       %prev_frame_data = merge_settings(\%default, \%prev_frame_data);
+       %next_frame_data = merge_settings(\%default, \%next_frame_data);
 }
 else {
        $access = 0;
@@ -318,6 +323,7 @@ print_viewer_page (
        \%state,
        \%settings,
        \%frame_data,
-       \%next_frame_data,
+       $access ? \%prev_frame_data : \%frame_data,
+       $access ? \%next_frame_data : \%frame_data,
        \%words_data,
 );