From: b Date: Thu, 11 Jan 2024 14:48:54 +0000 (+0000) Subject: preload previous page / frame X-Git-Tag: v1.0.0~10 X-Git-Url: http://bicyclesonthemoon.info/git-projects/?a=commitdiff_plain;h=5ea2bcd6821e1910391b6798d937c215a7524287;p=botm%2Foldlogs preload previous page / frame --- diff --git a/bsta_lib.1.pm b/bsta_lib.1.pm index b5301f0..fc71365 100644 --- a/bsta_lib.1.pm +++ b/bsta_lib.1.pm @@ -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 ' '."\n"; if ($prev_available) { print $fh ' '."\n"; + if ($prefetch_prev) { + print $fh ' '."\n"; + print $fh ' '."\n"; + } } if ($next_available) { print $fh ' '."\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 ); diff --git a/viewer.1.pl b/viewer.1.pl index 24a72b4..84a26bf 100644 --- a/viewer.1.pl +++ b/viewer.1.pl @@ -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, );