genorg.pl
changeset 8 ee9b57cbbefc
parent 7 f00ed34eca17
child 9 58b72fea234c
--- a/genorg.pl	Mon Dec 16 22:51:52 2024 +1000
+++ b/genorg.pl	Tue Dec 17 01:49:39 2024 +1000
@@ -19,6 +19,7 @@
 # Print required elisp code it is in $req_config
 # Add config option for $max_rss and $max_cat
 # Sort cataogirs by entires
+# Document link to file x from file x no work
 # Variable for map_css
 # Remove the desc
 # Domain thing as well
@@ -31,14 +32,16 @@
 my $dir = "blog";
 my $outdir = "out/";
 my $emacs = "emacs";
-my $css = "style.css";
-my $map_css ="other.css";
+my $art_css = "astyle.css";
+my $cat_css ="cstyle.css";
 my $no_name_dir = "c";
 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.
 my $max_cat = 7;
+my $main_title= "";
+my $blog_title = "Pranshu's blog";
 
 my $username = $ENV{LOGNAME} || $ENV{USER} || getpwuid ($<);
 my $template = <<"END";
@@ -77,6 +80,14 @@
 
 my $custom_code = "(list 1)";
 
+my $navbar = <<"END" =~ s/\n\s+//gr;
+<ul>
+  <li> Home
+  <li> Catagories
+  <li> About
+</ul>
+END
+
 my $elisp_code = <<"END" =~ s/\n\s+//gr;
 (let ((ls '(LIST)))
   (require 'org)
@@ -100,29 +111,27 @@
     <meta charset="UTF-8">
     <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <title>TITLE</title>
-    <link rel="stylesheet" href="style.css">
+    <link rel="stylesheet" href="CSS">
   </head>
+  <body>
+    NAV
+    <h1> BTIT </h1>
 SPLIT
-  <body>
-    <h1> Pranshu's Blog </h1>
     <ul id="cataogries">
 SPLIT 
       <li> <a href="LINK">  CATAG (NUMBER)</a>
 SPLIT
     </ul>
     <div>
-      <h2> All articles </h2> <hr>
+      <h2> All articles <a id="rss" href="rss.xml">(rss)</span> </h2> <hr>
 SPLIT
    <a href="LINK">
-     <strong> TITLE </strong> <span>DATE</span>
-     <p>DESCREPTION</p>
-     <i>CATAG</i>
+     <strong> TITLE </strong> <span>DATE</span> <i>CATAG</i>
      <hr>
   </a>
 SPLIT
    <a href="LINK">
      <strong> TITLE </strong> <span>DATE</span>
-     <p>DESCREPTION</p>
      <hr>
    </a>
 SPLIT
@@ -165,7 +174,7 @@
 my %config_vars =
   (
    'emacs-path' => \$emacs,
-   css => \$css,
+   css => \$art_css,
    indir => \$dir,
    outdir => \$outdir,
    no_name_dir => \$no_name_dir
@@ -279,23 +288,24 @@
 my $cache_dom;
 
 sub main {
-  -d $cdir or help_and_bye;
-  mkdir $outdir;
-  chdir $cdir or die "Couldn't access $cdir\n";
-  read_config $config_file;
-  -d $dir or die "$dir doesn't exist \n";
-  find (\&wanted, $dir);
-  for (@files_to_move) {
-    copy $_, s#$dir/?#$outdir#er;
-  }
-  mkdir for @files_to_make;
-  values %{conv_files()};
-  $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();
+    $outdir =~ s!/*$!/!;
+    -d $cdir or help_and_bye;
+    mkdir $outdir;
+    chdir $cdir or die "Couldn't access $cdir\n";
+    read_config $config_file;
+    -d $dir or die "$dir doesn't exist \n";
+    find (\&wanted, $dir);
+    for (@files_to_move) {
+	copy $_, s#$dir/?#$outdir#er;
+    }
+    mkdir for @files_to_make;
+    values %{conv_files()};
+    $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();
 }
 
 sub populate_cache {
@@ -304,12 +314,13 @@
   my %c_els;
   for my $art (@arts) {
     # We need the: related, file, date
-    my ($art_el, $date, $title, $ca, $related) =
-      map {$dom->createElement($_)} ("art", "date", "title", "catag", "related");
+    my ($art_el, $date, $title, $ca, $related, $utitle) =
+      map {$dom->createElement($_)} ("art", "date", "title", "catag", "related", "utitle");
     $art_el->{path} = $art->{file};
     $ca->appendText($art->{catag});
     $title->appendText($art->{title});
     $date->appendText($art->{date}->text_easy);
+    $utitle->appendText($art->{utitle});
     my @ll = @{$art->{links}};
     if (@ll) {
       my $links = $dom->createElement('links');
@@ -329,7 +340,7 @@
 	$related->appendText("\"$catag\"" . ($artt && "->\"$artt\" "));
       }
     }
-    $art_el->appendChild($_) for ($date, $ca, $related, $title);
+    $art_el->appendChild($_) for ($date, $ca, $related, $title, $utitle);
     $root->appendChild($art_el);
   }
   $root->appendChild($_) for values %c_els;
@@ -345,7 +356,7 @@
     ? ($h_en_cat =~ s/CATAG/$data->{catag}/er) : $h_en;
   my $prel_path = "/$no_name_dir/" . (defined $catagory ? "c" : "c/b");
   $str =~ s/DATE/$data->{date}->fmt/er
-    =~ s/TITLE/$data->{title}/er
+    =~ s/TITLE/$data->{utitle}/er
     =~ s|LINK|prel_path($prel_path, '/'. $data->{file})|er
   }
 
@@ -357,8 +368,9 @@
     <description>DESC</description>
   </item>
 END
-  $thing =~ s|LINK|"$domain/" . $data->{file}|er
-    =~ s/TITLE/$data->{title}/er;
+  $thing 
+    =~ s|LINK|"$domain/" . $data->{file}|er
+      =~ s/TITLE/$data->{utitle}/er;
 }
 
 sub min ($x, $y) {
@@ -370,7 +382,7 @@
   my $page = shift;
   '<ul>' . join ("", map {
     my ($str, $file) = @{$_};
-    $str = "---$str" if $file && ($file == $page);
+    $str = "<span class=\"psel\">$str</span>" if $file && ($file == $page);
     defined $file ?
       "<li><a href=\"$file.html\">$str</a>" : $str
     } ((["←", $page - 1]) x!! ($page - 1),
@@ -416,14 +428,22 @@
   }
 }
 
+sub cssbs($s,$t,$p){
+  $s =~ s|CSS|prel_path("/$p","/$cat_css")|er
+    =~ s/TITLE|BTIT/$t/ger
+    =~ s/NAV/$navbar/er;
+}
+
 sub finalise_html {
   mkdir $no_name_dir;
   open my $fh, '>', "$no_name_dir/1.html";
   open my $mrss, '>', "$no_name_dir/rss.xml"; # The master rss file
   print $mrss $rss_entry;
-  print $fh $h_intro . $h_c_intro;
+  print $fh cssbs($h_intro . $h_c_intro, $blog_title, "a/c");
   my (%c_files, %r_files);	# Cataogry files and rss
-  while (my ($cat, $num) = each %catags) {
+  
+  for my $cat (sort { $catags{$b} <=> $catags{$a} } keys(%catags)) {
+    my $num = $catags{$cat};
     # ($h_intro, $h_c_intro, $h_cat_li, $h_chap, $h_en_cat, $h_en, $h_end)
     print $fh $h_cat_li =~ s/NUMBER/$num/re
       =~ s/CATAG/$cat/er
@@ -432,7 +452,8 @@
     open $c_files{$cat}, '>', "$no_name_dir/$cat/1.html";
     open $r_files{$cat}, '>', "$no_name_dir/$cat/rss.xml";
     print {$r_files{$cat}} $rss_entry;
-    print {$c_files{$cat}} $h_intro;
+    print {$c_files{$cat}}
+      cssbs($h_intro, "$cat  <a id=\"rss\" href=\"rss.xml\">(rss)</span> ", "a/b/c");
   }
   print $fh $h_chap;
   # :-)
@@ -441,6 +462,7 @@
   my ($n_fh, $n_mrss, %n_rss) = (0,0);
   my %n_cat;
   for my $art (@arts) {
+    # TODO do we need $title?
     my ($catag, $title) = @{$art}{qw(catag title)};
     my $rentry = rss_en $art;
     if (($n_rss{$catag} // 0) < $max_rss) {
@@ -461,7 +483,6 @@
     $$cfh = move_on_if_neccasary $$cfh, $$ncat, $catags{$catag}, "$no_name_dir/$catag";
     print {$$cfh} entry $art;
     my $a_file = $art->{file};
-    # say $a_file;
     if (1 or grep /^$a_file$/, @modified_files) {
       my $doom = linkify($art);
       open my $h_file, '>', $a_file;
@@ -502,7 +523,6 @@
     push @links, $key;
     my $l = get_art(@{$key})->{file} or die "Link not found in $art->{filename}\n";
     $_->{href} = prel_path("/".$art->{file}, "/$l");
-    print $_;
   }
   $art->{links} = \@links;
   return $bom
@@ -516,10 +536,10 @@
   for my $d ($cache_dom->findnodes("/root/art[\@path=\"$fn\"]")) {
     # TODO related
     my %dome = ('file' => $fn);
-    (@dome{'title', 'catag'}, my $date) =
+    (@dome{'title', 'catag', 'utitle'}, my $date) =
       map
       { $d->getChildrenByTagName($_)->[0]->to_literal }
-      qw[title catag date];
+      qw[title catag  utitle date];
     for ($d->getChildrenByTagName("links")) {
       my @ll = map [$_->{catag}, $_->to_literal],
 	($_->getChildrenByTagName('link'));
@@ -533,16 +553,13 @@
 }
 
 sub html_fixup ($filename) {
-  # for (getcache($filename)) {
-  # $_ && return $_;
-  # }
-  unless (!$cache && grep /^$filename$/, @modified_files) {
+  if ($cache && !grep /^$filename$/, @modified_files) {
     for (getcache($filename)) {
       return $_ if $_
     }
   }
   my $dom =
-    XML::LibXML->load_html(location  => $filename, recover   => 1);
+    XML::LibXML->load_html(location  => $filename);
   my %data = ('file', $filename);
 
   # We don't need style or table of contents heading (if exists)
@@ -562,9 +579,11 @@
       $p->parentNode->removeChild($p);
     }
   }
-  # Title\
+  # Title
+  say "HELLO";
   for ($dom->findnodes('/html/head/title')) {
-    $data{title}  = $_->to_literal;
+    say "HERE";
+    $data{utitle}  = $_->to_literal;
   }
   # keywords/catogry
   for my $node ($dom->findnodes('/html/head/meta')) {