# HG changeset patch # User Pranshu Sharma # Date 1734452323 -36000 # Node ID 31e45dd2a8942693b3b36f84fb8f49b309bb293e # Parent da3b9ba1a7f01dcb820e73fe77418efa920e7290 fixup diff -r da3b9ba1a7f0 -r 31e45dd2a894 genorg.pl --- a/genorg.pl Wed Dec 18 00:58:13 2024 +1000 +++ b/genorg.pl Wed Dec 18 02:18:43 2024 +1000 @@ -37,34 +37,24 @@ 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 = 30; my $blog_title = "Pranshu's blog"; my ($home, $about) = ("home.html", "about.html"); my $etc_files; my $nav_id = "nav"; +my $rdesc = "description"; my $username = $ENV{LOGNAME} || $ENV{USER} || getpwuid ($<); my $template = <<"END"; #+title: Test document #+subtitle: This is the subtitle +#+date: IMPORANT #+author: $username -#+keywords: tag thing | related +#+keywords: tag->thing | rel->a #+options: html-link-use-abs-url:nil html-postamble:auto #+options: html-preamble:t html-scripts:nil html-style:t #+options: html5-fancy:nil tex:t -#+options: tex:mathjax #+html_doctype: html5 -#+html_container: div -#+html_content_class: content -#+html_link_home: -#+html_link_up: -#+html_mathjax: -#+html_equation_reference_format: \eqref{%s} -#+html_head: -#+html_head_extra: -#+infojs_opt: -#+creator: Emacs 31.0.50 (Org mode 9.7.11) -#+latex_header: END my $req_config = <<"END"; @@ -153,7 +143,8 @@ VAR VALUE where VAR can be: emacs-path : The value should be path of emacs. 'emacs' by default. - css : The path of the css file to use. + acss : The path of the css file to use for articles. + ccss : Path of css to use for cataogry pages. in_dir : The directory that contains the files. out_dir : the output directory. no_name_dir: The directory for generate files. This means in_dir/no_name_dir @@ -164,6 +155,8 @@ about : about file domain : domain (for rss) title : title of the blog + max_rss : max_rss entries + max_cat : max catagory entries before next page As soon as config file comes accross '>>---', the rest of the file is now the elisp code used in emacs startup. @@ -174,15 +167,16 @@ - W3Schools Home Page - https://www.w3schools.com - Free web building tutorials" + TITLE + BLINK + RDESC" END my %config_vars = ( 'emacs-path' => \$emacs, - css => \$art_css, + acss => \$art_css, + ccss => \$cat_css, indir => \$dir, outdir => \$outdir, no_name_dir => \$no_name_dir, @@ -191,7 +185,10 @@ home => \$home, about => \$about, domain => \$domain, - title => \&blog_title + title => \$blog_title, + rdesc => \$rdesc, + max_rss => \$max_rss, + max_cat => \$max_cat ); @@ -206,10 +203,10 @@ } chomp; my ($directive, $rest) = split /\s+/, $_, 2; - if (exists($config_vars{$directive})) { + if (exists $config_vars{$directive}) { ${$config_vars{$directive}} = $rest; } else { - print "Unknown variable $directive\n"; + die "Unknown variable $directive\n"; } } close $fh; @@ -221,7 +218,7 @@ } sub template ($file) { - $file // die "-t needs an argument.\n"; + $file // do {print $template; exit(1)}; $file =~ s/\.org$//; open my $fh, '>', $file . ".org" or die $file . " couldn't be opened\n"; print $fh $template; @@ -230,7 +227,7 @@ # Reletive file from the perspect of file1, to file2 sub prel_path ($from, $to) { - return $to =~ s/^.//r if $from eq $to; + return $to if $from eq $to; my \(@f1, @f2) = map [m{/[^/]+}g], ($from, $to); # return substr($f1[$#f1], 1) if $from =~ $to; while (@f1 && @f2 && $f1[0] =~ $f2[0]) { @@ -304,35 +301,35 @@ my $cache_dom; sub main { - s!/*$!/! for ($outdir, $dir); - -d $cdir or help_and_bye; - mkdir $outdir; - chdir $cdir or die "Couldn't access $cdir\n"; - read_config $config_file; - my @navify_files = map {"$dir$_"} ($about, $home, $etc_files ? split(/[ \t]+/, $etc_files) : ()); - -d $dir or die "$dir doesn't exist \n"; - find (\&wanted, $dir); - for my $f (@files_to_move) { - my $dest = $f =~ s#$dir/?#$outdir#er; - if (grep(m#^$f$#, @navify_files)) { - # YAY we have to sub navbar and copy whoop whoop - open my $file_tc, '<', $f or die "file no open, grrr!"; - open my $file_out, '>', $dest; - local $/; - print $file_out ((<$file_tc>) =~ s/NAV/nav_up("$dest" =~ s%.+?\/%%r,1)/er); - map \&close, ($file_tc, $file_out); - } else { - copy $f, $dest; - } + -d $cdir or help_and_bye; + mkdir $outdir; + chdir $cdir or die "Couldn't access $cdir\n"; + read_config $config_file; + s!/*$!/! for ($outdir, $dir); + my @navify_files = map {"$dir$_"} ($about, $home, $etc_files ? split(/[ \t]+/, $etc_files) : ()); + -d $dir or die "$dir doesn't exist \n"; + find (\&wanted, $dir); + for my $f (@files_to_move) { + my $dest = $f =~ s#$dir/?#$outdir#er; + if (grep(m#^$f$#, @navify_files)) { + # YAY we have to sub navbar and copy whoop whoop + open my $file_tc, '<', $f or die "file no open, grrr!"; + open my $file_out, '>', $dest; + local $/; + print $file_out ((<$file_tc>) =~ s/NAV/nav_up("$dest" =~ s%.+?\/%%r,1)/er); + map \&close, ($file_tc, $file_out); + } else { + copy $f, $dest; } - 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(); + } + 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 { @@ -460,14 +457,14 @@ sub nav_up { my ($path) = @_; my @links = ($home, 'c/1.html', $about); - my $nav = shift ? $navbar : "
$navbar
"; + my $nav = shift ? "
$navbar
" : $navbar; $nav =~ s#LINK#prel_path("/$path", "/". shift @links)#ger; } sub cssbs($s,$t,$p){ $s =~ s|CSS|prel_path("/$p","/$cat_css")|er =~ s/TITLE|BTIT/$t/ger - =~ s/NAV/nav_up($p)/er; + =~ s/NAV/nav_up($p,1)/er; } sub modify_art ($file, $dom) { @@ -478,7 +475,7 @@ for ($dom->findnodes('/html/body')) { # my @cds = $_->childNodes; my $nav_el = $dom->createElement('div'); - $nav_el->{id} = $nav_id; + $nav_el->{class} = $nav_id; $nav_el->appendWellBalancedChunk(nav_up($file)); $_->insertBefore($nav_el, $_->childNodes->[0]) } @@ -491,11 +488,18 @@ $dom; } +sub rss_st { + $rss_entry + =~ s/TITLE/$blog_title/er + =~ s/BLINK/$domain/er + =~ s/RDESC/$rdesc/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 $mrss rss_st(); print $fh cssbs($h_intro . $h_c_intro, $blog_title, "a/c"); my (%c_files, %r_files); # Cataogry files and rss @@ -508,7 +512,7 @@ mkdir "$no_name_dir/$cat"; 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 {$r_files{$cat}} rss_st(); print {$c_files{$cat}} cssbs($h_intro, "$cat (rss) ", "a/b/c"); }