genorg.pl
changeset 4 c98c7c32ab46
parent 3 bf4ae6f1dbbf
child 5 24fc5a406138
--- a/genorg.pl	Sat Dec 14 16:22:55 2024 +1000
+++ b/genorg.pl	Sun Dec 15 20:38:17 2024 +1000
@@ -18,8 +18,10 @@
 # Add config option for $max_rss and $max_cat
 # Sort cataogirs by entires
 # Variable for map_css
+# Remove the desc
 # Domain thing as well
 # Load custom filpe for htmlize and all that
+# 2 articles 1 day better sorting
 my $cache = 1;
 
 my $config_file = "genorg-conf";
@@ -29,7 +31,7 @@
 my $css = "style.css";
 my $map_css ="other.css";
 my $no_name_dir = "c";
-my $cache_file = ".genorg/cache.xml";
+my $cache_file = "genorg-cache/cache.xml";
 my $domain = "p.bauherren.ovh";
 my $max_rss = 30;
 # The first page has one less article.  Think of it as a feature.
@@ -270,7 +272,7 @@
   find (\&wanted, $dir);
   mkdir for @files_to_make;
   values %{conv_files()};
-  # my $cache_dom = XML::LibXML->load_xml(location => $cache_dom) if $cache && -f $cache_file;
+  my $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;
   chdir '..';
@@ -280,12 +282,31 @@
 
 sub populate_cache {
   my $dom = XML::LibXML::Document->new('1.0', 'UTF-8');
-  my $title = $dom->createElement('title');
+  my $root = $dom->createElement('root');
+  my %c_els;
   for my $art (@arts) {
-    print Dumper($art);
+    # We need the: related, file, date
+    my ($art_el, $date, $title, $ca, $related) =
+      map {$dom->createElement($_)} ("art", "date", "title", "catag", "related");
+    $art_el->{path} = $art->{file};
+    $ca->appendText($art->{catag});
+    $title->appendText($art->{title});
+    $date->appendText($art->{date}->text_easy);
+    my $rel_str;
+    for my $thing ($art->{related}) {
+      for (@{$thing}) {
+	my ($catag, $artt) = @{$_};
+	my $rel_str .= "\"$catag\"" . ($artt && "->\"$artt\"");
+	$related->appendText("\"$catag\"" . ($artt && "->\"$artt\" "));
+      }
+    }
+    $art_el->appendChild($_) for ($date, $ca, $related);
+    $root->appendChild($art_el);
   }
+  $root->appendChild($_) for values %c_els;
+  $dom->setDocumentElement($root);
   open my $fh, '>' ,$cache_file;
-  print $fh $dom->toString;
+  print $fh ($dom->toString(1) =~ s/(.+)/$1\n<!-- Nicley formated :() -->/r);
   close $fh;
 }
 
@@ -430,15 +451,22 @@
   }
 }
 
+# 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 {
-  
+  $cache_dom || return 0;
+  return 0;
 }
 
 sub html_fixup ($filename) {
-  # I don't want to prepopulate, as it is not known which ones are
-  # usless and outdated
-  for (getcache($filename)) {
-    $_ && return $_;
+   # for (getcache($filename)) {
+    # $_ && return $_;
+  # }
+  unless (grep /^$filename$/, @modified_files) {
+    for (getcache($filename)) {
+      return $_ if $_
+    }
   }
   my $dom =
     XML::LibXML->load_html(location  => $filename, recover   => 1);
@@ -540,6 +568,9 @@
     my $self = shift;
     join "-", ($self->{year}, $self->{month}, $self->{day});
   }
-
+  sub text_easy {
+    my $self = shift;
+    join "-", ($self->{year}, $self->{month}, $self->{day});
+  }
 }