From 9dab789a464f24f3c05e126c335bd9d65692882f Mon Sep 17 00:00:00 2001 From: b Date: Sat, 9 Mar 2024 22:01:14 +0000 Subject: [PATCH] use relative URLs in HTML of posts --- bb2html.1.awk | 6 ++++++ bot2m.1.pl | 24 ++++++++++++++++-------- config | 2 +- settings-debug.txt | 5 +++-- settings-release.txt | 1 + settings.txt | 2 ++ 6 files changed, 29 insertions(+), 11 deletions(-) diff --git a/bb2html.1.awk b/bb2html.1.awk index 76cf7ef..2781d29 100644 --- a/bb2html.1.awk +++ b/bb2html.1.awk @@ -281,7 +281,12 @@ function bb2html(text, depth,count,bbtree,html,tag,tagstart,taglength,elm,tagv } } else if (tagname == "img") + { + ++count[depth] + sub(###AWK_own_url_regexp;, "/", bbtree[ind(count,depth)]) + --count[depth] html=html"" } else if (tagname == "size") diff --git a/bot2m.1.pl b/bot2m.1.pl index 2edbb57..ab41141 100644 --- a/bot2m.1.pl +++ b/bot2m.1.pl @@ -1,4 +1,4 @@ -# Copyright (C) 2023 Balthasar Szczepański +# Copyright (C) 2023, 2024 Balthasar Szczepański # bot2m.pl automatically generated from bot2m.1.pl # This file is part of OTT mirror. @@ -28,7 +28,7 @@ use botm_common ( 'html_entity_decode', 'url_decode', 'merge_url', - 'system_encoded' + 'system_encoded', 'readdir_decoded', 'opendir_encoded' ); use post_common ( 'wget' @@ -38,6 +38,7 @@ use post_common ( ###PERL_OWN_DOMAIN: use constant OWN_DOMAIN => '1190.bicyclesonthemoon.info' ###PERL_WWW_IMG_PATH: use constant WWW_IMG_PATH => '/botm/www/1190/ott/image' ###PERL_IMG_URL: use constant IMG_URL => 'http://1190.bicyclesonthemoon.info/ott/image' +###PERL_OWN_URL: use constant OWN_URL => 'http://1190.bicyclesonthemoon.info/ott' ###PERL_TMP_PATH: use constant TMP_PATH => '/botm/tmp/post'; ###PERL_WAYBACK: use constant WAYBACK => 'http://web.archive.org/web/'; ###PERL_BIN_IMG_PATH: use constant BIN_IMG_PATH => '/botm/bin/ottmirror/image'; @@ -52,19 +53,26 @@ binmode STDERR, ':encoding(console_out)'; decode_argv(); my $dh; -if (opendir $dh, encode('locale_fs', MPOST_PATH)) { - my @fl = readdir $dh; # <-- encoding??? +my $force = 0; +if ((scalar @ARGV) > 0) { + if ($ARGV[0] eq '--force') { + # TODO: better --force handling + $force = 1; + } +} +if (opendir_encoded($dh, MPOST_PATH())) { + my @fl = readdir_decoded($dh); closedir $dh; foreach my $fn (@fl) { if ($fn =~ /^[0-9]+$/) { - my %post = read_data_file(join_path('/',MPOST_PATH,$fn), 'utf8'); + my %post = read_data_file(join_path('/',MPOST_PATH,$fn)); if ($post{'disable_bbcode'}) { next; } - my $changed = 0; + my $changed = $force; my $message = $post{'bb'}; my $new_message = ''; $message =~ s//\n/gs; @@ -128,8 +136,8 @@ if (opendir $dh, encode('locale_fs', MPOST_PATH)) { else { $new_post{'notify'} = '0'; } - write_data_file($tmp_file, 'utf8', 0, \%new_post); - my $r = system_encoded(SENDPOST, (SENDPOST, '--mirror', '--edit=m'.$fn, $tmp_file)); + write_data_file($tmp_file, \%new_post); + my $r = system_encoded(SENDPOST, (SENDPOST, '--mirror', '--edit=m'.$fn, $tmp_file, '--mirror-url='.OWN_URL())); unlink $tmp_file; } } diff --git a/config b/config index fc9affe..778dbca 160000 --- a/config +++ b/config @@ -1 +1 @@ -Subproject commit fc9affec336a16cde93b2675a836bdd01d1c2210 +Subproject commit 778dbca76f413af0b5d2c442a482b4d4eebaf2cb diff --git a/settings-debug.txt b/settings-debug.txt index 6031ffd..fa2dcbf 100644 --- a/settings-debug.txt +++ b/settings-debug.txt @@ -35,10 +35,11 @@ smiley_regexp : ((url.\.)|(((href)|(src))=.http:\/\/((for(ums3?|a)\.xkcd\.com smiley_regexp2 : ((\.)|(http:\/\/((for(ums3?|a)\.xkcd\.com)|echochamber\.me)))\/images\/smilies avatar_regexp : ((src)|(href))=.http:\/\/((for(ums3?|a)\.xkcd\.com)|echochamber\.me)\/download\/file.php\?avatar= attachment_regexp: ((src)|(href))=.http:\/\/(www\.)?((for(ums3?|a)\.xkcd\.com)|echochamber\.me)\/download\/file.php\?(mode=view\&)?id= -own_image_regexp : ((1190.bicyclesonthemoon.(dnsd.)?info)|(1190-botm.dnsdynamic.com))\/ott\/image\/ +own_image_regexp : ((1190.bicyclesonthemoon.(dnsd.)?info)|(1190-botm.dnsdynamic.com))\/ottest\/image\/ +own_domain_regexp: ((1190.bicyclesonthemoon.(dnsd.)?info)|(1190-botm.dnsdynamic.com)|(moonbase.chirpingmustard.com)) own_domain : 1190.bicyclesonthemoon.info -own_url : http://1190.bicyclesonthemoon.info/ott +own_url : http://1190.bicyclesonthemoon.info/ottest bot3name : bothasar_p bot3_url : http://1190.bicyclesonthemoon.info/bothasar_p/ default_subject: Re: 1190: "Time" diff --git a/settings-release.txt b/settings-release.txt index 48adc7f..8e99640 100644 --- a/settings-release.txt +++ b/settings-release.txt @@ -36,6 +36,7 @@ smiley_regexp2 : ((\.)|(http:\/\/((for(ums3?|a)\.xkcd\.com)|echochamber\.me))) avatar_regexp : ((src)|(href))=.http:\/\/((for(ums3?|a)\.xkcd\.com)|echochamber\.me)\/download\/file.php\?avatar= attachment_regexp: ((src)|(href))=.http:\/\/(www\.)?((for(ums3?|a)\.xkcd\.com)|echochamber\.me)\/download\/file.php\?(mode=view\&)?id= own_image_regexp : ((1190.bicyclesonthemoon.(dnsd.)?info)|(1190-botm.dnsdynamic.com))\/ottest\/image\/ +own_domain_regexp: ((1190.bicyclesonthemoon.(dnsd.)?info)|(1190-botm.dnsdynamic.com)|(moonbase.chirpingmustard.com)) own_domain : 1190.bicyclesonthemoon.info own_url : http://1190.bicyclesonthemoon.info/ottest diff --git a/settings.txt b/settings.txt index 71fe976..e8e68b4 100644 --- a/settings.txt +++ b/settings.txt @@ -229,6 +229,7 @@ AWK_avatar_regexp = /$avatar_regexp/ AWK_bot3name_encoded = @_ESCAPE($_bot3name_encoded) AWK_links_regexp = /$links_regexp/ AWK_own_image_regexp = /$own_image_regexp/ +AWK_own_url_regexp = /^https?:\\/\\/$own_domain_regexp\\// AWK_own_url_encoded = @_ESCAPE($_own_url_encoded) AWK_prosilver_regexp = /$prosilver_regexp/ AWK_prosilver_regexp2 = /$prosilver_regexp2/ @@ -358,6 +359,7 @@ PERL_MPOST_PATH = @_PERL_CONSTANT_STR( MPOST_PATH , $_mem_post_path) PERL_OWN_DOMAIN = @_PERL_CONSTANT_STR( OWN_DOMAIN , $own_domain) PERL_WWW_IMG_PATH = @_PERL_CONSTANT_STR( WWW_IMG_PATH, $_www_img_path) PERL_IMG_URL = @_PERL_CONSTANT_STR( IMG_URL , $_url_img) +PERL_OWN_URL = @_PERL_CONSTANT_STR( OWN_URL , $own_url) PERL_TMP_PATH = @_PERL_CONSTANT_STR( TMP_PATH , $tmp_path) PERL_WAYBACK = @_PERL_CONSTANT_STR( WAYBACK , $wayback_addr) PERL_BIN_IMG_PATH = @_PERL_CONSTANT_STR( BIN_IMG_PATH, $_bin_image_path) -- 2.30.2