diff -r ee9b57cbbefc -r 58b72fea234c genorg.pl --- a/genorg.pl Tue Dec 17 01:49:39 2024 +1000 +++ b/genorg.pl Wed Dec 18 00:35:02 2024 +1000 @@ -39,9 +39,11 @@ 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 $max_cat = 10; my $blog_title = "Pranshu's blog"; +my ($home, $about) = ("home.html", "about.html"); +my $etc_files; +my $nav_id = "nav"; my $username = $ENV{LOGNAME} || $ENV{USER} || getpwuid ($<); my $template = <<"END"; @@ -82,9 +84,9 @@ my $navbar = <<"END" =~ s/\n\s+//gr; END @@ -98,8 +100,7 @@ (eq major-mode 'org-mode)) (org-export-to-file 'html (pop ls))))) (buffer-list)) - (kill-emacs) -) + (kill-emacs)) END @@ -177,7 +178,8 @@ css => \$art_css, indir => \$dir, outdir => \$outdir, - no_name_dir => \$no_name_dir + no_name_dir => \$no_name_dir, + etc_files => \$etc_files ); @@ -216,7 +218,7 @@ # Reletive file from the perspect of file1, to file2 sub prel_path ($from, $to) { - return '.' if $from eq $to; + return $to =~ s/^.//r 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]) { @@ -231,6 +233,7 @@ my @org_exps; my @files_to_make; my @files_to_move; +my @navify_files; sub wanted { my $n_path = $outdir . prel_path ($dir, "$File::Find::name/"); @@ -245,6 +248,7 @@ } else { push @files_to_move, $File::Find::name } + } my @modified_files; @@ -288,15 +292,27 @@ my $cache_dom; sub main { - $outdir =~ s!/*$!/!; + 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 (@files_to_move) { - copy $_, s#$dir/?#$outdir#er; + 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; + say $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()}; @@ -390,11 +406,13 @@ (["→", $page + 1]) x ($page != $_[$#_]->[1]))) . '' } -sub move_on_if_neccasary ($fh, $art_num, $total_articles, $path) { +sub move_on_if_neccasary ($fh, $art_num, $total_articles, $path, $title, $rp) { return $fh if $art_num == 0 || $art_num % $max_cat; my $cpage = $art_num / $max_cat; print $fh panigation($cpage, ceil($total_articles / $max_cat), $path); open $fh, '>', $path . '/' . ($cpage + 1).'.html'; + # ($h_intro . $h_c_intro, $blog_title, "a/c"); + print $fh cssbs($h_intro, $title, $rp); $fh; } @@ -428,10 +446,38 @@ } } +sub nav_up { + my ($path) = @_; + my @links = ($home, 'c/1.html', $about); + 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/$navbar/er; + =~ s/NAV/nav_up($p)/er; +} + +sub modify_art ($file, $dom) { + # I guess we can rely on navbar not changed, if it did then user + # would need to call with -d option + return $dom unless grep /^$file$/, @modified_files; + # We add css, navbar + for ($dom->findnodes('/html/body')) { + # my @cds = $_->childNodes; + my $nav_el = $dom->createElement('div'); + $nav_el->{id} = $nav_id; + $nav_el->appendWellBalancedChunk(nav_up($file)); + $_->insertBefore($nav_el, $_->childNodes->[0]) + } + for ($dom->findnodes('/html/head')) { + my $link = $dom->createElement('link'); + $link->{rel} = "stylesheet"; + $link->{href} = prel_path("/$file", "/$art_css"); + $_->appendChild($link); + } + $dom; } sub finalise_html { @@ -474,17 +520,19 @@ ++$n_mrss } # ($fh, $art_num, $total_articles, $path) - $fh = move_on_if_neccasary $fh, $n_fh, $total_articles, $no_name_dir; + $fh = move_on_if_neccasary + $fh, $n_fh, $total_articles, $no_name_dir, "All articles", "a/c"; $n_fh++; print $fh entry $art, 1; my $ncat = \$n_cat{$catag}; ++$$ncat; my $cfh = \$c_files{$catag}; - $$cfh = move_on_if_neccasary $$cfh, $$ncat, $catags{$catag}, "$no_name_dir/$catag"; + $$cfh = move_on_if_neccasary + $$cfh, $$ncat, $catags{$catag}, "$no_name_dir/$catag", $catag, "a/c/b"; print {$$cfh} entry $art; my $a_file = $art->{file}; if (1 or grep /^$a_file$/, @modified_files) { - my $doom = linkify($art); + my $doom = modify_art($a_file, linkify($art)); open my $h_file, '>', $a_file; print $h_file $doom->toStringHTML; close $h_file; @@ -580,9 +628,7 @@ } } # Title - say "HELLO"; for ($dom->findnodes('/html/head/title')) { - say "HERE"; $data{utitle} = $_->to_literal; } # keywords/catogry