293 $thing =~ s|LINK|"$domain/" . $data->{file}|er |
293 $thing =~ s|LINK|"$domain/" . $data->{file}|er |
294 =~ s/TITLE/$data->{title}/er |
294 =~ s/TITLE/$data->{title}/er |
295 =~ s/DESC/$data->{desc}/er; |
295 =~ s/DESC/$data->{desc}/er; |
296 } |
296 } |
297 |
297 |
298 sub make_h_list { |
|
299 my $rstr = '<ul>'; |
|
300 for (@_) { |
|
301 my ($str, $page_no) = @{$_}; |
|
302 $rstr .= "<li> <a href=\"$page_no.html\"> $str </a>"; |
|
303 } |
|
304 $rstr . "</ul>" |
|
305 } |
|
306 |
|
307 sub min ($x, $y) { |
298 sub min ($x, $y) { |
308 ($x, $y)[$x > $y] |
299 ($x, $y)[$x > $y] |
309 } |
300 } |
310 |
301 |
311 sub panigation ($total_arts, $page_no) { |
302 # @_ has to be in format of [STRING, LINK] |
312 if ($total_arts < 9) { |
303 sub list2paginaiton { |
313 make_h_list ((['«', $page_no - 1]) x!! ($page_no - 1), |
304 my $page = shift; |
314 (map [$_ == $page_no ? "<span>$_</span>" : $_, $_ ], |
305 '<ul>' . join ("", map { |
315 (1..($total_arts + 1))), |
306 my ($str, $file) = @{$_}; |
316 ['»', $page_no]) |
307 defined $file ? |
317 } |
308 "<li><a href=\"$file.html\">$str</a>" : $str |
318 } |
309 } ((["←", $page - 1]) x!! ($page - 1), |
319 |
310 @_, |
320 sub move_on($article, $cfh, $next_file, $total_arts) { |
311 (["→", $page + 1]) x ($page != $_[$#_]->[1]))) . '</ul>' |
321 # say "Article is ". $article; |
312 } |
322 my $page = 1 + int $article / $max_cat; |
313 |
323 print $cfh panigation int($total_arts / $max_cat), $page; |
314 sub panigation ($page, $no_pages, $dir) { |
324 print $cfh $h_end; |
315 say "HERE"; |
325 close $cfh; |
316 if ($no_pages < 10) { |
326 open $cfh, '>', "$next_file$page.html"; |
317 say "There"; |
327 say "$next_file$page.html"; |
318 list2paginaiton ($page, (map [$_ == $page ? "---$_" : $_, $_], (1..$no_pages))) |
328 print $cfh $h_intro; |
319 } else { |
329 $cfh |
320 list2paginaiton |
|
321 (# (["←", $page - 1]) x!! ($page - 1) , |
|
322 [1, 1], |
|
323 ["<li>..."], |
|
324 (map [$_ == $page ? "---$_" : $_, $_], (($page-2)..($page+2))), |
|
325 ["<li>..."], |
|
326 [($no_pages) x 2], |
|
327 # (["→", $page + 1]) x ($page != $no_pages) |
|
328 ) |
|
329 } |
|
330 } |
|
331 |
|
332 sub move_on_if_neccasary ($fh, $art_num, $total_articles, $path) { |
|
333 return $fh if $art_num == 0 || $art_num % $max_cat; |
|
334 my $cpage = $art_num / $max_cat; |
|
335 # saypani "\$cpage is $cpage is $art_num / $max_cat"; |
|
336 print $fh panigation($cpage, int 0.6 + $total_articles / $max_cat, $path); |
|
337 open $fh, '>', $path . '/' . ($cpage + 1).'.html'; |
|
338 $fh; |
330 } |
339 } |
331 |
340 |
332 sub finalise_html { |
341 sub finalise_html { |
333 mkdir $no_name_dir; |
342 mkdir $no_name_dir; |
334 open my $fh, '>', "$no_name_dir/1.html"; |
343 open my $fh, '>', "$no_name_dir/1.html"; |
362 if ($n_mrss < $max_rss) { |
371 if ($n_mrss < $max_rss) { |
363 print $mrss $rentry; |
372 print $mrss $rentry; |
364 ++$n_mrss |
373 ++$n_mrss |
365 } |
374 } |
366 # my $ncat = \$n_cat{$catag}; |
375 # my $ncat = \$n_cat{$catag}; |
|
376 # ($fh, $art_num, $total_articles, $path) |
|
377 $fh = move_on_if_neccasary $fh, $n_fh, $total_articles, $no_name_dir; |
367 $n_fh++; |
378 $n_fh++; |
368 if ($n_fh % $max_cat == 0) { |
|
369 say "$n_fh % $max_cat = " . $n_fh % $max_cat ; |
|
370 say "\$n_fh is $n_fh"; |
|
371 $fh = move_on($n_fh, $fh, "$no_name_dir/", $total_articles); |
|
372 } |
|
373 print $fh entry $art, 1; |
379 print $fh entry $art, 1; |
374 print {$c_files{$catag}} entry $art; |
380 print {$c_files{$catag}} entry $art; |
375 # say "$catag -> $title($n_cat{$catag})"; |
381 # say "$catag -> $title($n_cat{$catag})"; |
376 # say ($n_cat{$catag} // 1); |
382 # say ($n_cat{$catag} // 1); |
377 # ++$$ncat |
383 # ++$$ncat |
378 } |
384 } |
379 # ($total_arts, $page_no) |
385 print $fh panigation (($n_fh / $max_cat) x 2, $no_name_dir) if $max_cat < $total_articles; |
380 print $fh panigation ((int $total_articles / $max_cat) x 2) if $total_articles >= $max_cat; |
|
381 print $fh $h_end; |
386 print $fh $h_end; |
382 close $fh; |
387 close $fh; |
383 for (values %c_files) { |
388 for (values %c_files) { |
384 print $_ $h_end; |
389 print $_ $h_end; |
385 close; |
390 close; |