From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 386421F725 for ; Thu, 30 Nov 2023 11:41:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1701344471; bh=W0TbsU0Q7/BHc2Qj6pt+6UrCXZqWShWTJ8HCVz8RmL8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=zaMC/nNzek076XCtaT6mrVARgcRgsietIydELkDXVHhsSsYAEkoQ29xGm8Jf52J+h cM2/xwIkRDyJWthxaT0tQmn1nobw5vIcmK8y4eLjg6yYZzhcn5AlZdKrVrBcYKotq0 ClP5I8cUtMOm3r6Mx4+ZRypzLrroivi2BZ1INZzM= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 13/15] www_listing: support publicInbox.nameIsUrl Date: Thu, 30 Nov 2023 11:41:06 +0000 Message-ID: <20231130114109.2577708-14-e@80x24.org> In-Reply-To: <20231130114109.2577708-1-e@80x24.org> References: <20231130114109.2577708-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: This is a convenient (and slightly memory-saving) alternative to specifying a `publicinbox.*.url' entry for every single inbox when using publicinbox.wwwListing. --- Documentation/public-inbox-config.pod | 19 ++++++++++++++++++- lib/PublicInbox/WwwListing.pm | 21 +++++++++++++-------- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/Documentation/public-inbox-config.pod b/Documentation/public-inbox-config.pod index d394d31f..d2017704 100644 --- a/Documentation/public-inbox-config.pod +++ b/Documentation/public-inbox-config.pod @@ -273,7 +273,9 @@ Default: 25 A comma-delimited list of listings to hide the inbox from. -Valid values are currently C and C. +Valid values are currently C and C for non-C<404> +values of L and L, +respectively Default: none @@ -379,6 +381,21 @@ TODO support showing cgit listing Default: C<404> +=item publicinbox.nameIsUrl + +Treat the name of the public inbox as it's unqualified URL when +using C. This is, every +C<[publicinbox "foo"]> section implicitly sets C. + +This is a convenient alternative to specifying +CnameE.url> for every single inbox if +your inbox URLs are domain-agnostic when using +C + +Default: false + +New in public-inbox 2.0.0 (PENDING). + =item publicinbox.grokmanifest Controls the generation of a grokmirror-compatible gzipped JSON file diff --git a/lib/PublicInbox/WwwListing.pm b/lib/PublicInbox/WwwListing.pm index 21e5b8bc..e3d2e84c 100644 --- a/lib/PublicInbox/WwwListing.pm +++ b/lib/PublicInbox/WwwListing.pm @@ -41,10 +41,7 @@ sub list_match_i { # ConfigIter callback if (defined($section)) { return if $section !~ m!\Apublicinbox\.([^/]+)\z!; my $ibx = $cfg->lookup_name($1) or return; - if (!$ibx->{-hide}->{$ctx->hide_key} && - grep(/$re/, @{$ibx->{url} // []})) { - $ctx->ibx_entry($ibx); - } + $ctx->ibx_entry($ibx) unless $ctx->hide_inbox($ibx, $re); } else { # undef == "EOF" $ctx->{-wcb}->($ctx->psgi_triple); } @@ -54,13 +51,17 @@ sub url_filter { my ($ctx, $key, $default) = @_; $key //= 'publicInbox.wwwListing'; $default //= '404'; - my $v = $ctx->{www}->{pi_cfg}->{lc $key} // $default; + my $cfg = $ctx->{www}->{pi_cfg}; + my $v = $cfg->{lc $key} // $default; again: if ($v eq 'match=domain') { my $h = $ctx->{env}->{HTTP_HOST} // $ctx->{env}->{SERVER_NAME}; $h =~ s/:[0-9]+\z//; (qr!\A(?:https?:)?//\Q$h\E(?::[0-9]+)?/!i, "url:$h"); } elsif ($v eq 'all') { + my $niu = $cfg->{lc 'publicinbox.nameIsUrl'}; + defined($niu) && $cfg->git_bool($niu) and + $ctx->{-name_is_url} = [ '.' ]; (qr/./, undef); } elsif ($v eq '404') { (undef, undef); @@ -76,6 +77,12 @@ EOF sub hide_key { 'www' } +sub hide_inbox { + my ($ctx, $ibx, $re) = @_; + $ibx->{-hide}->{$ctx->hide_key} || + !grep(/$re/, @{$ibx->{url} // $ctx->{-name_is_url} // []}) +} + sub add_misc_ibx { # MiscSearch->retry_reopen callback my ($misc, $ctx, $re, $qs) = @_; require PublicInbox::SearchQuery; @@ -104,15 +111,13 @@ sub add_misc_ibx { # MiscSearch->retry_reopen callback $ctx->ibx_entry($pi_cfg->ALL // die('BUG: ->ALL expected'), {}); } my $mset = $misc->mset($qs, $opt); # sorts by $MODIFIED (mtime) - my $hide_key = $ctx->hide_key; for my $mi ($mset->items) { my $doc = $mi->get_document; my ($eidx_key) = PublicInbox::Search::xap_terms('Q', $doc); $eidx_key // next; my $ibx = $pi_cfg->lookup_eidx_key($eidx_key) // next; - next if $ibx->{-hide}->{$hide_key}; - grep(/$re/, @{$ibx->{url} // []}) or next; + next if $ctx->hide_inbox($ibx, $re); $ctx->ibx_entry($ibx, $misc->doc2ibx_cache_ent($doc)); if ($r) { # for descriptions in search_nav_bot my $pct = PublicInbox::Search::get_pct($mi);