diff -r c98c7c32ab46 -r 24fc5a406138 genorg.pl --- a/genorg.pl Sun Dec 15 20:38:17 2024 +1000 +++ b/genorg.pl Sun Dec 15 22:45:46 2024 +1000 @@ -11,6 +11,7 @@ use Cwd; use experimental qw(declared_refs); use Data::Dumper; +use POSIX; # Fix up CLI interface # Add option ro set cache to 0 through command line @@ -35,7 +36,7 @@ my $domain = "p.bauherren.ovh"; my $max_rss = 30; # The first page has one less article. Think of it as a feature. -my $max_cat = 10; +my $max_cat = 7; my $username = $ENV{LOGNAME} || $ENV{USER} || getpwuid ($<); my $template = <<"END"; @@ -71,9 +72,12 @@ :store nil)) END +my $custom_code = "(require 'ob-dot) (setq org-confirm-babel-evaluate nil)"; + my $elisp_code = <<"END" =~ s/\n\s+//gr; (let ((ls '(LIST))) (require 'org) + $custom_code (mapc (lambda (b) (with-current-buffer b @@ -272,12 +276,12 @@ find (\&wanted, $dir); mkdir for @files_to_make; values %{conv_files()}; - my $cache_dom = XML::LibXML->load_xml(location => $cache_file) if $cache && -f $cache_file; + $cache_dom = XML::LibXML->load_xml(location => $cache_file) if $cache && -f $cache_file; chdir $outdir; @arts = sort { $b->{date} <=> $a->{date}} map { html_fixup($_) } @org_exps; + finalise_html(); chdir '..'; populate_cache(); - # finalise_html(); } sub populate_cache { @@ -300,12 +304,12 @@ $related->appendText("\"$catag\"" . ($artt && "->\"$artt\" ")); } } - $art_el->appendChild($_) for ($date, $ca, $related); + $art_el->appendChild($_) for ($date, $ca, $related, $title); $root->appendChild($art_el); } $root->appendChild($_) for values %c_els; $dom->setDocumentElement($root); - open my $fh, '>' ,$cache_file; + open my $fh, '>' , $cache_file; print $fh ($dom->toString(1) =~ s/(.+)/$1\n/r); close $fh; } @@ -317,21 +321,19 @@ my $prel_path = "/$no_name_dir/" . (defined $catagory ? "c" : "c/b"); $str =~ s/DATE/$data->{date}->fmt/er =~ s/TITLE/$data->{title}/er - =~ s/DESCREPTION/$data->{desc}/er =~ s|LINK|prel_path($prel_path, '/'. $data->{file})|er } sub rss_en ($data) { my $thing = <<"END" =~ s/\n\s+//gr; - + TITLE LINK DESC END $thing =~ s|LINK|"$domain/" . $data->{file}|er - =~ s/TITLE/$data->{title}/er - =~ s/DESC/$data->{desc}/er; + =~ s/TITLE/$data->{title}/er; } sub min ($x, $y) { @@ -354,17 +356,15 @@ 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; - print $fh panigation($cpage, int 0.6 + $total_articles / $max_cat, $path); + print $fh panigation($cpage, ceil($total_articles / $max_cat), $path); open $fh, '>', $path . '/' . ($cpage + 1).'.html'; $fh; } sub panigation ($page, $no_pages, $dir) { - say ($no_pages - 4); if ($no_pages < 9) { list2paginaiton ($page, (map [$_, $_], (1..$no_pages))) } elsif (4 < $page <= ($no_pages - 4)) { - say "HERE"; list2paginaiton ($page, [1, 1], @@ -385,6 +385,10 @@ } } +sub linkify ($bom) { + $bom +} + sub finalise_html { mkdir $no_name_dir; open my $fh, '>', "$no_name_dir/1.html"; @@ -433,11 +437,12 @@ # say $a_file; if (grep /^$a_file$/, @modified_files) { open my $h_file, '>', $a_file; - # print $h_file $art->{dom}->toString; + my $doom = linkify $art->{dom}; + print $h_file $doom->toString; close $h_file; } } - print $fh panigation (($n_fh / $max_cat) x 2, $no_name_dir) if $max_cat < $total_articles; + print $fh panigation ((ceil $n_fh / $max_cat) x 2, $no_name_dir) if $max_cat < $total_articles; print $fh $h_end; close $fh; for (values %c_files) { @@ -454,16 +459,27 @@ # I don't want to prepopulate, as it is not known which ones are # usless and outdated, and it would be a waste of cycles parsing # something to know it is not needed -sub getcache { +sub getcache ($fn) { $cache_dom || return 0; + for my $d ($cache_dom->findnodes("/root/art[\@path=\"$fn\"]")) { + # TODO related + my %dome = ('file' => $fn); + (@dome{'title', 'catag'}, my $date) = + map + { $d->getChildrenByTagName($_)->[0]->to_literal } + qw[title catag date]; + $catags{$dome{catag}}++; + $dome{date} = PDate->new(split /-/, $date); + return \%dome; + } return 0; } sub html_fixup ($filename) { - # for (getcache($filename)) { - # $_ && return $_; + # for (getcache($filename)) { + # $_ && return $_; # } - unless (grep /^$filename$/, @modified_files) { + unless ($cache && grep /^$filename$/, @modified_files) { for (getcache($filename)) { return $_ if $_ } @@ -497,9 +513,7 @@ for my $node ($dom->findnodes('/html/head/meta')) { (my $cont = $node->getAttribute('content')) || next; for ($node->getAttribute('name')) { - if (/description/) { - $data{desc} = $cont; - } elsif (/keywords/) { + if (/keywords/) { my ($key, $rest) = parse_keywords($cont); @data{qw[catag title]} = @{$key}; $catags{$data{catag}}++; @@ -560,7 +574,7 @@ if ($n == 1) { $n = '1st' } elsif (($n - 2) % 10 == 0) { $n = "${n}nd" } elsif (($n - 3) % 10 == 0) { $n = "${n}rd" } - else { $n = "${n}st" } + else { $n = "${n}th" } $months[$self->{month} - 1] . " $n, " . $self->{year} }