10 use File::Copy qw(copy move); |
10 use File::Copy qw(copy move); |
11 use Cwd; |
11 use Cwd; |
12 use experimental qw(declared_refs); |
12 use experimental qw(declared_refs); |
13 use Data::Dumper; |
13 use Data::Dumper; |
14 use POSIX; |
14 use POSIX; |
|
15 # !! Add seperatio between title and identifier |
15 |
16 |
16 # Fix up CLI interface |
17 # Fix up CLI interface |
17 # Add option ro set cache to 0 through command line |
18 # Add option ro set cache to 0 through command line |
18 # Print required elisp code it is in $req_config |
19 # Print required elisp code it is in $req_config |
19 # Add config option for $max_rss and $max_cat |
20 # Add config option for $max_rss and $max_cat |
20 # Sort cataogirs by entires |
21 # Sort cataogirs by entires |
21 # Variable for map_css |
22 # Variable for map_css |
22 # Remove the desc |
23 # Remove the desc |
23 # Domain thing as well |
24 # Domain thing as well |
24 # Load custom filpe for htmlize and all that |
|
25 # 2 articles 1 day better sorting |
25 # 2 articles 1 day better sorting |
|
26 # cataogry linking |
|
27 # reinforce slash ending for $oudir |
26 my $cache = 1; |
28 my $cache = 1; |
27 |
29 |
28 my $config_file = "genorg-conf"; |
30 my $config_file = "genorg-conf"; |
29 my $dir = "blog"; |
31 my $dir = "blog"; |
30 my $outdir = "out/"; |
32 my $outdir = "out/"; |
280 mkdir $outdir; |
283 mkdir $outdir; |
281 chdir $cdir or die "Couldn't access $cdir\n"; |
284 chdir $cdir or die "Couldn't access $cdir\n"; |
282 read_config $config_file; |
285 read_config $config_file; |
283 -d $dir or die "$dir doesn't exist \n"; |
286 -d $dir or die "$dir doesn't exist \n"; |
284 find (\&wanted, $dir); |
287 find (\&wanted, $dir); |
|
288 for (@files_to_move) { |
|
289 copy $_, s#$dir/?#$outdir#er; |
|
290 } |
285 mkdir for @files_to_make; |
291 mkdir for @files_to_make; |
286 values %{conv_files()}; |
292 values %{conv_files()}; |
287 $cache_dom = XML::LibXML->load_xml(location => $cache_file) if $cache && -f $cache_file; |
293 $cache_dom = XML::LibXML->load_xml(location => $cache_file) if $cache && -f $cache_file; |
288 chdir $outdir; |
294 chdir $outdir; |
289 @arts = sort { $b->{date} <=> $a->{date}} map { html_fixup($_) } @org_exps; |
295 @arts = sort { $b->{date} <=> $a->{date}} map { html_fixup($_) } @org_exps; |
302 map {$dom->createElement($_)} ("art", "date", "title", "catag", "related"); |
308 map {$dom->createElement($_)} ("art", "date", "title", "catag", "related"); |
303 $art_el->{path} = $art->{file}; |
309 $art_el->{path} = $art->{file}; |
304 $ca->appendText($art->{catag}); |
310 $ca->appendText($art->{catag}); |
305 $title->appendText($art->{title}); |
311 $title->appendText($art->{title}); |
306 $date->appendText($art->{date}->text_easy); |
312 $date->appendText($art->{date}->text_easy); |
|
313 my @ll = @{$art->{links}}; |
|
314 if (@ll) { |
|
315 my $links = $dom->createElement('links'); |
|
316 for (@ll) { |
|
317 my $link = $dom->createElement("link"); |
|
318 $link->{catag} = $_->[0]; |
|
319 $link->appendText($_->[1]); |
|
320 $links->appendChild($link); |
|
321 } |
|
322 $art_el->appendChild($links); |
|
323 } |
307 my $rel_str; |
324 my $rel_str; |
308 for my $thing ($art->{related}) { |
325 for my $thing ($art->{related}) { |
309 for (@{$thing}) { |
326 for (@{$thing}) { |
310 my ($catag, $artt) = @{$_}; |
327 my ($catag, $artt) = @{$_}; |
311 my $rel_str .= "\"$catag\"" . ($artt && "->\"$artt\""); |
328 my $rel_str .= "\"$catag\"" . ($artt && "->\"$artt\""); |
441 my $cfh = \$c_files{$catag}; |
460 my $cfh = \$c_files{$catag}; |
442 $$cfh = move_on_if_neccasary $$cfh, $$ncat, $catags{$catag}, "$no_name_dir/$catag"; |
461 $$cfh = move_on_if_neccasary $$cfh, $$ncat, $catags{$catag}, "$no_name_dir/$catag"; |
443 print {$$cfh} entry $art; |
462 print {$$cfh} entry $art; |
444 my $a_file = $art->{file}; |
463 my $a_file = $art->{file}; |
445 # say $a_file; |
464 # say $a_file; |
446 if (grep /^$a_file$/, @modified_files) { |
465 if (1 or grep /^$a_file$/, @modified_files) { |
|
466 my $doom = linkify($art); |
447 open my $h_file, '>', $a_file; |
467 open my $h_file, '>', $a_file; |
448 my $doom = linkify $art->{dom}; |
468 print $h_file $doom->toStringHTML; |
449 print $h_file $doom->toString; |
|
450 close $h_file; |
469 close $h_file; |
451 } |
470 } |
452 } |
471 } |
453 print $fh panigation ((ceil $n_fh / $max_cat) x 2, $no_name_dir) if $max_cat < $total_articles; |
472 print $fh panigation ((ceil $n_fh / $max_cat) x 2, $no_name_dir) if $max_cat < $total_articles; |
454 print $fh $h_end; |
473 print $fh $h_end; |
455 close $fh; |
474 close $fh; |
456 for (values %c_files) { |
475 for (values %c_files) { |
457 print $_ $h_end; |
476 print $_ $h_end; |
458 close; |
477 close $_; |
459 } |
478 } |
460 print $mrss '</channel> </rss>'; |
479 print $mrss '</channel> </rss>'; |
461 for (values %r_files) { |
480 for (values %r_files) { |
462 print $_ '</channel> </rss>';; |
481 print $_ '</channel> </rss>';; |
463 close; |
482 close $_; |
464 } |
483 } |
|
484 } |
|
485 |
|
486 sub linkify ($art) { |
|
487 # if $art->{dom} is undefined, we must sadly parse again |
|
488 my @links; |
|
489 my @olinks = @{$art->{links} //[]}; |
|
490 my $bom = $art->{dom} // XML::LibXML->load_html(location => $art->{file}); |
|
491 for ($bom->findnodes('//a[@class="rakim"]')) { |
|
492 my $key; |
|
493 my $link_text; |
|
494 if (@olinks) { |
|
495 $key = pop @olinks; |
|
496 } else { |
|
497 ($key) = parse_keywords($_->to_literal); |
|
498 $link_text = $_->{href}; |
|
499 $_->removeChild($_->firstChild()); |
|
500 $_->appendText($link_text); |
|
501 } |
|
502 push @links, $key; |
|
503 my $l = get_art(@{$key})->{file} or die "Link not found in $art->{filename}\n"; |
|
504 $_->{href} = prel_path("/".$art->{file}, "/$l"); |
|
505 print $_; |
|
506 } |
|
507 $art->{links} = \@links; |
|
508 return $bom |
465 } |
509 } |
466 |
510 |
467 # I don't want to prepopulate, as it is not known which ones are |
511 # I don't want to prepopulate, as it is not known which ones are |
468 # usless and outdated, and it would be a waste of cycles parsing |
512 # usless and outdated, and it would be a waste of cycles parsing |
469 # something to know it is not needed |
513 # something to know it is not needed |
474 my %dome = ('file' => $fn); |
518 my %dome = ('file' => $fn); |
475 (@dome{'title', 'catag'}, my $date) = |
519 (@dome{'title', 'catag'}, my $date) = |
476 map |
520 map |
477 { $d->getChildrenByTagName($_)->[0]->to_literal } |
521 { $d->getChildrenByTagName($_)->[0]->to_literal } |
478 qw[title catag date]; |
522 qw[title catag date]; |
|
523 for ($d->getChildrenByTagName("links")) { |
|
524 my @ll = map [$_->{catag}, $_->to_literal], |
|
525 ($_->getChildrenByTagName('link')); |
|
526 $dome{links} = \@ll; |
|
527 } |
479 $catags{$dome{catag}}++; |
528 $catags{$dome{catag}}++; |
480 $dome{date} = PDate->new(split /-/, $date); |
529 $dome{date} = PDate->new(split /-/, $date); |
481 return \%dome; |
530 return \%dome; |
482 } |
531 } |
483 return 0; |
532 return 0; |