From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 478351FB06 for ; Thu, 26 Aug 2021 12:33:39 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 5/8] www_text: fix example config snippet for extindex Date: Thu, 26 Aug 2021 12:33:35 +0000 Message-Id: <20210826123338.694-6-e@80x24.org> In-Reply-To: <20210826123338.694-1-e@80x24.org> References: <20210826123338.694-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: extindex doesn't use the same config stuff as normal "publicinbox" entries, so we'll need a separate function for them. --- lib/PublicInbox/WwwText.pm | 29 ++++++++++++++++++++++++++++- t/extindex-psgi.t | 12 ++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/lib/PublicInbox/WwwText.pm b/lib/PublicInbox/WwwText.pm index db5060ea..eb5e3ac7 100644 --- a/lib/PublicInbox/WwwText.pm +++ b/lib/PublicInbox/WwwText.pm @@ -214,10 +214,37 @@ EOF 1; } +# n.b. this is a perfect candidate for memoization +sub extindex_config ($$$) { + my ($ctx, $hdr, $txt) = @_; + my $ibx = $ctx->{ibx}; + push @$hdr, 'Content-Disposition', 'inline; filename=extindex.config'; + my $name = dq_escape($ibx->{name}); + my $base_url = $ibx->base_url($ctx->{env}); + $$txt .= <{$k}) or next; + $$txt .= "\t$k = $v\n"; + } + # TODO: coderepo support for extindex + 1; +} + sub _default_text ($$$$) { my ($ctx, $key, $hdr, $txt) = @_; return _colors_help($ctx, $txt) if $key eq 'color'; - return inbox_config($ctx, $hdr, $txt) if $key eq 'config'; + $key eq 'config' and return $ctx->{ibx}->can('cloneurl') ? + inbox_config($ctx, $hdr, $txt) : + extindex_config($ctx, $hdr, $txt); return if $key ne 'help'; # TODO more keys? my $ibx = $ctx->{ibx}; diff --git a/t/extindex-psgi.t b/t/extindex-psgi.t index 6f62b5a0..b9acc979 100644 --- a/t/extindex-psgi.t +++ b/t/extindex-psgi.t @@ -40,6 +40,18 @@ my $client = sub { 'Host: header respected in Atom feed'); unlike($res->content, qr!http://bogus\.example\.com/!s, 'default URL ignored with different host header'); + + $res = $cb->(GET('/all/_/text/config/')); + is($res->code, 200, '/text/config HTML'); + $res = $cb->(GET('/all/_/text/config/raw')); + is($res->code, 200, '/text/config raw'); + my $f = "$tmpdir/extindex.config"; + open my $fh, '>', $f or xbail $!; + print $fh $res->content or xbail $!; + close $fh or xbail $!; + my $cfg = PublicInbox::Config->git_config_dump($f); + is($?, 0, 'no errors from git-config parsing'); + ok($cfg->{'extindex.all.topdir'}, 'extindex.topdir defined'); }; test_psgi(sub { $www->call(@_) }, $client); %$env = (%$env, TMPDIR => $tmpdir, PI_CONFIG => $pi_config);