genorg.pl
changeset 22 dc1add4ee525
parent 21 f61879daacf0
equal deleted inserted replaced
21:f61879daacf0 22:dc1add4ee525
    77   <li> <a href="LINK">About</a>  </li>
    77   <li> <a href="LINK">About</a>  </li>
    78 </ul>
    78 </ul>
    79 END
    79 END
    80 
    80 
    81 my $elisp_code = <<"END" =~ s/\n\s+//gr;
    81 my $elisp_code = <<"END" =~ s/\n\s+//gr;
    82   (let ((ls '(LIST)))
    82 (let ((ls '(LIST)))
    83     (require 'org)
    83   (require 'org)
    84     (mapc
    84   (mapc
    85     (lambda (b)
    85    (lambda (b)
    86     (with-current-buffer b
    86      (with-current-buffer b
    87     (when (and (not (string-match "^ " (buffer-name b)))
    87        (when (and (not (string-match "^ " (buffer-name b)))
    88     (eq major-mode 'org-mode))
    88 		  (eq major-mode 'org-mode))
    89     (org-export-to-file 'html (pop ls)))))
    89 	 (org-export-to-file 'html (pop ls)))))
    90     (buffer-list))
    90    (buffer-list))
    91     (kill-emacs))
    91    (kill-emacs))
    92 END
    92 END
    93 
    93 
    94 
    94 
    95 my ($h_intro, $h_c_intro, $h_cat_li, $h_chap, $h_en_cat, $h_en, $h_end)
    95 my ($h_intro, $h_c_intro, $h_cat_li, $h_chap, $h_en_cat, $h_en, $h_end)
    96   = split /SPLIT/ ,<<"END" =~ s/\n\s+//gr;
    96   = split /SPLIT/ ,<<"END" =~ s/\n\s+//gr;
   171   <link>BLINK</link>
   171   <link>BLINK</link>
   172 END
   172 END
   173   
   173   
   174 my %config_vars =
   174 my %config_vars =
   175   (
   175   (
   176   'emacs-path' => \$emacs,
   176    'emacs-path' => \$emacs,
   177   acss => \$art_css,
   177    acss => \$art_css,
   178   ccss => \$cat_css,
   178    ccss => \$cat_css,
   179   indir => \$dir,
   179    indir => \$dir,
   180   outdir => \$outdir,
   180    outdir => \$outdir,
   181   no_name_dir => \$no_name_dir,
   181    no_name_dir => \$no_name_dir,
   182   etc_files => \$etc_files,
   182    etc_files => \$etc_files,
   183   cache => \$cache_file,
   183    cache => \$cache_file,
   184   home => \$home,
   184    home => \$home,
   185   about => \$about,
   185    about => \$about,
   186   domain => \$domain,
   186    domain => \$domain,
   187   title => \$blog_title,
   187    title => \$blog_title,
   188   rdesc => \$rdesc,
   188    rdesc => \$rdesc,
   189   max_rss => \$max_rss,
   189    max_rss => \$max_rss,
   190   max_cat => \$max_cat
   190    max_cat => \$max_cat
   191   );
   191   );
   192 
   192 
   193 
   193 
   194 sub read_config ($path) {
   194 sub read_config ($path) {
   195   open my $fh, '<', $path or die "Couldn't open config file\n";
   195   open my $fh, '<', $path or die "Couldn't open config file\n";
   271     s/org$/html/ for ($to, $rel_file);
   271     s/org$/html/ for ($to, $rel_file);
   272     unless ($cache && -f $to && (stat($to))[9] > (stat($file))[9]) {
   272     unless ($cache && -f $to && (stat($to))[9] > (stat($file))[9]) {
   273       $changed_files{$file} = $to;
   273       $changed_files{$file} = $to;
   274       push @modified_files, $rel_file;
   274       push @modified_files, $rel_file;
   275     }
   275     }
   276     %changed_files // exit;
   276   }
   277     $elisp_code =~ s/LIST/join '', map "\"$_\" ", values %changed_files /e;
   277   %changed_files // exit;
   278     open my $fh,
   278   $elisp_code =~ s/LIST/join '', map "\"$_\" ", values %changed_files /e;
   279       '-|',
   279   open my $fh, '-|', ($emacs, '-Q','--eval', "(progn $custom_code)", keys %changed_files, "--eval" , "$elisp_code");
   280       ($emacs,
   280   close $fh;
   281        '-Q',
   281   \%changed_files
   282        '--eval',
   282 }
   283        "(progn $custom_code)",
       
   284        keys %changed_files,
       
   285        "--eval",
       
   286        "$elisp_code");
       
   287     close $fh;
       
   288     \%changed_files
       
   289   }
       
   290 
   283 
   291 my $cdir;
   284 my $cdir;
   292 
   285 
   293 $ARGV[0] // die "No arguments provided\n";
   286 $ARGV[0] // die "No arguments provided\n";
   294 while ($_ = shift @ARGV) {
   287 while ($_ = shift @ARGV) {
   412   '<ul>' . join ("", map {
   405   '<ul>' . join ("", map {
   413     my ($str, $file) = @{$_};
   406     my ($str, $file) = @{$_};
   414     $str = "<span class=\"psel\">$str</span>" if $file && ($file == $page);
   407     $str = "<span class=\"psel\">$str</span>" if $file && ($file == $page);
   415     defined $file ?
   408     defined $file ?
   416       "<li><a href=\"$file.html\">$str</a>" : $str
   409       "<li><a href=\"$file.html\">$str</a>" : $str
   417   } ((["←", $page - 1]) x!! ($page - 1),
   410     } ((["←", $page - 1]) x!! ($page - 1),
   418      @_,
   411        @_,
   419      (["→", $page + 1]) x ($page != $_[$#_]->[1]))) . '</ul>'
   412        (["→", $page + 1]) x ($page != $_[$#_]->[1]))) . '</ul>'
   420 }
   413      }
   421 
   414 
   422 sub move_on_if_neccasary ($fh, $art_num, $total_articles, $path, $title, $rp) {
   415 sub move_on_if_neccasary ($fh, $art_num, $total_articles, $path, $title, $rp) {
   423   return $fh if $art_num == 0 || $art_num % $max_cat;
   416   return $fh if $art_num == 0 || $art_num % $max_cat;
   424   my $cpage = $art_num / $max_cat;
   417   my $cpage = $art_num / $max_cat;
   425   print $fh panigation($cpage, ceil($total_articles / $max_cat), $path);
   418   print $fh panigation($cpage, ceil($total_articles / $max_cat), $path);