genorg.pl
changeset 4 c98c7c32ab46
parent 3 bf4ae6f1dbbf
child 5 24fc5a406138
equal deleted inserted replaced
3:bf4ae6f1dbbf 4:c98c7c32ab46
    16 # Add option ro set cache to 0 through command line
    16 # Add option ro set cache to 0 through command line
    17 # Print required elisp code it is in $req_config
    17 # Print required elisp code it is in $req_config
    18 # Add config option for $max_rss and $max_cat
    18 # Add config option for $max_rss and $max_cat
    19 # Sort cataogirs by entires
    19 # Sort cataogirs by entires
    20 # Variable for map_css
    20 # Variable for map_css
       
    21 # Remove the desc
    21 # Domain thing as well
    22 # Domain thing as well
    22 # Load custom filpe for htmlize and all that
    23 # Load custom filpe for htmlize and all that
       
    24 # 2 articles 1 day better sorting
    23 my $cache = 1;
    25 my $cache = 1;
    24 
    26 
    25 my $config_file = "genorg-conf";
    27 my $config_file = "genorg-conf";
    26 my $dir = "blog";
    28 my $dir = "blog";
    27 my $outdir = "out/";
    29 my $outdir = "out/";
    28 my $emacs = "emacs";
    30 my $emacs = "emacs";
    29 my $css = "style.css";
    31 my $css = "style.css";
    30 my $map_css ="other.css";
    32 my $map_css ="other.css";
    31 my $no_name_dir = "c";
    33 my $no_name_dir = "c";
    32 my $cache_file = ".genorg/cache.xml";
    34 my $cache_file = "genorg-cache/cache.xml";
    33 my $domain = "p.bauherren.ovh";
    35 my $domain = "p.bauherren.ovh";
    34 my $max_rss = 30;
    36 my $max_rss = 30;
    35 # The first page has one less article.  Think of it as a feature.
    37 # The first page has one less article.  Think of it as a feature.
    36 my $max_cat = 10;
    38 my $max_cat = 10;
    37 
    39 
   268   read_config $config_file;
   270   read_config $config_file;
   269   -d $dir or die "$dir doesn't exist \n";
   271   -d $dir or die "$dir doesn't exist \n";
   270   find (\&wanted, $dir);
   272   find (\&wanted, $dir);
   271   mkdir for @files_to_make;
   273   mkdir for @files_to_make;
   272   values %{conv_files()};
   274   values %{conv_files()};
   273   # my $cache_dom = XML::LibXML->load_xml(location => $cache_dom) if $cache && -f $cache_file;
   275   my $cache_dom = XML::LibXML->load_xml(location => $cache_file) if $cache && -f $cache_file;
   274   chdir $outdir;
   276   chdir $outdir;
   275   @arts = sort { $b->{date} <=> $a->{date}} map { html_fixup($_) } @org_exps;
   277   @arts = sort { $b->{date} <=> $a->{date}} map { html_fixup($_) } @org_exps;
   276   chdir '..';
   278   chdir '..';
   277   populate_cache();
   279   populate_cache();
   278   # finalise_html();
   280   # finalise_html();
   279 }
   281 }
   280 
   282 
   281 sub populate_cache {
   283 sub populate_cache {
   282   my $dom = XML::LibXML::Document->new('1.0', 'UTF-8');
   284   my $dom = XML::LibXML::Document->new('1.0', 'UTF-8');
   283   my $title = $dom->createElement('title');
   285   my $root = $dom->createElement('root');
       
   286   my %c_els;
   284   for my $art (@arts) {
   287   for my $art (@arts) {
   285     print Dumper($art);
   288     # We need the: related, file, date
   286   }
   289     my ($art_el, $date, $title, $ca, $related) =
       
   290       map {$dom->createElement($_)} ("art", "date", "title", "catag", "related");
       
   291     $art_el->{path} = $art->{file};
       
   292     $ca->appendText($art->{catag});
       
   293     $title->appendText($art->{title});
       
   294     $date->appendText($art->{date}->text_easy);
       
   295     my $rel_str;
       
   296     for my $thing ($art->{related}) {
       
   297       for (@{$thing}) {
       
   298 	my ($catag, $artt) = @{$_};
       
   299 	my $rel_str .= "\"$catag\"" . ($artt && "->\"$artt\"");
       
   300 	$related->appendText("\"$catag\"" . ($artt && "->\"$artt\" "));
       
   301       }
       
   302     }
       
   303     $art_el->appendChild($_) for ($date, $ca, $related);
       
   304     $root->appendChild($art_el);
       
   305   }
       
   306   $root->appendChild($_) for values %c_els;
       
   307   $dom->setDocumentElement($root);
   287   open my $fh, '>' ,$cache_file;
   308   open my $fh, '>' ,$cache_file;
   288   print $fh $dom->toString;
   309   print $fh ($dom->toString(1) =~ s/(.+)/$1\n<!-- Nicley formated :() -->/r);
   289   close $fh;
   310   close $fh;
   290 }
   311 }
   291 
   312 
   292 sub entry {
   313 sub entry {
   293   my ($data, $catagory) = @_;
   314   my ($data, $catagory) = @_;
   428     print $_ '</channel> </rss>';;
   449     print $_ '</channel> </rss>';;
   429     close;
   450     close;
   430   }
   451   }
   431 }
   452 }
   432 
   453 
       
   454 # I don't want to prepopulate, as it is not known which ones are
       
   455 # usless and outdated, and it would be a waste of cycles parsing
       
   456 # something to know it is not needed
   433 sub getcache {
   457 sub getcache {
   434   
   458   $cache_dom || return 0;
       
   459   return 0;
   435 }
   460 }
   436 
   461 
   437 sub html_fixup ($filename) {
   462 sub html_fixup ($filename) {
   438   # I don't want to prepopulate, as it is not known which ones are
   463    # for (getcache($filename)) {
   439   # usless and outdated
   464     # $_ && return $_;
   440   for (getcache($filename)) {
   465   # }
   441     $_ && return $_;
   466   unless (grep /^$filename$/, @modified_files) {
       
   467     for (getcache($filename)) {
       
   468       return $_ if $_
       
   469     }
   442   }
   470   }
   443   my $dom =
   471   my $dom =
   444     XML::LibXML->load_html(location  => $filename, recover   => 1);
   472     XML::LibXML->load_html(location  => $filename, recover   => 1);
   445   my %data = ('file', $filename);
   473   my %data = ('file', $filename);
   446 
   474 
   538     
   566     
   539   sub short_fmt {
   567   sub short_fmt {
   540     my $self = shift;
   568     my $self = shift;
   541     join "-", ($self->{year}, $self->{month}, $self->{day});
   569     join "-", ($self->{year}, $self->{month}, $self->{day});
   542   }
   570   }
   543 
   571   sub text_easy {
   544 }
   572     my $self = shift;
   545 
   573     join "-", ($self->{year}, $self->{month}, $self->{day});
       
   574   }
       
   575 }
       
   576