# HG changeset patch # User Pranshu Sharma # Date 1734095734 -36000 # Node ID c4ca65113229f0a0b8f8dfc2c8b1de203a5debf3 # Parent 0b7be2e78d3b6aeb53b45f443d2dffef0e7aa60b Pagination major progress diff -r 0b7be2e78d3b -r c4ca65113229 genorg.pl --- a/genorg.pl Fri Dec 13 00:46:06 2024 +1000 +++ b/genorg.pl Fri Dec 13 23:15:34 2024 +1000 @@ -295,38 +295,47 @@ =~ s/DESC/$data->{desc}/er; } -sub make_h_list { - my $rstr = '" -} - sub min ($x, $y) { ($x, $y)[$x > $y] } -sub panigation ($total_arts, $page_no) { - if ($total_arts < 9) { - make_h_list ((['«', $page_no - 1]) x!! ($page_no - 1), - (map [$_ == $page_no ? "$_" : $_, $_ ], - (1..($total_arts + 1))), - ['»', $page_no]) - } +# @_ has to be in format of [STRING, LINK] +sub list2paginaiton { + my $page = shift; + '' + } + +sub panigation ($page, $no_pages, $dir) { + say "HERE"; + if ($no_pages < 10) { + say "There"; + list2paginaiton ($page, (map [$_ == $page ? "---$_" : $_, $_], (1..$no_pages))) + } else { + list2paginaiton + (# (["←", $page - 1]) x!! ($page - 1) , + [1, 1], + ["
  • ..."], + (map [$_ == $page ? "---$_" : $_, $_], (($page-2)..($page+2))), + ["
  • ..."], + [($no_pages) x 2], + # (["→", $page + 1]) x ($page != $no_pages) + ) + } } -sub move_on($article, $cfh, $next_file, $total_arts) { - # say "Article is ". $article; - my $page = 1 + int $article / $max_cat; - print $cfh panigation int($total_arts / $max_cat), $page; - print $cfh $h_end; - close $cfh; - open $cfh, '>', "$next_file$page.html"; - say "$next_file$page.html"; - print $cfh $h_intro; - $cfh +sub move_on_if_neccasary ($fh, $art_num, $total_articles, $path) { + return $fh if $art_num == 0 || $art_num % $max_cat; + my $cpage = $art_num / $max_cat; + # saypani "\$cpage is $cpage is $art_num / $max_cat"; + print $fh panigation($cpage, int 0.6 + $total_articles / $max_cat, $path); + open $fh, '>', $path . '/' . ($cpage + 1).'.html'; + $fh; } sub finalise_html { @@ -364,20 +373,16 @@ ++$n_mrss } # my $ncat = \$n_cat{$catag}; + # ($fh, $art_num, $total_articles, $path) + $fh = move_on_if_neccasary $fh, $n_fh, $total_articles, $no_name_dir; $n_fh++; - if ($n_fh % $max_cat == 0) { - say "$n_fh % $max_cat = " . $n_fh % $max_cat ; - say "\$n_fh is $n_fh"; - $fh = move_on($n_fh, $fh, "$no_name_dir/", $total_articles); - } print $fh entry $art, 1; print {$c_files{$catag}} entry $art; # say "$catag -> $title($n_cat{$catag})"; # say ($n_cat{$catag} // 1); # ++$$ncat } - # ($total_arts, $page_no) - print $fh panigation ((int $total_articles / $max_cat) x 2) if $total_articles >= $max_cat; + print $fh panigation (($n_fh / $max_cat) x 2, $no_name_dir) if $max_cat < $total_articles; print $fh $h_end; close $fh; for (values %c_files) {