]> Sergey Matveev's repositories - public-inbox.git/commitdiff
www_text: fix example config snippet for extindex
authorEric Wong <e@80x24.org>
Thu, 26 Aug 2021 12:33:35 +0000 (12:33 +0000)
committerEric Wong <e@80x24.org>
Sat, 28 Aug 2021 10:37:01 +0000 (10:37 +0000)
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
t/extindex-psgi.t

index db5060eaa460bf002c4377b93eb1b14c1cd5c7ba..eb5e3ac7b3edf49a0a049ab2503cd3e5c59798a0 100644 (file)
@@ -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 .= <<EOS;
+; Example public-inbox config snippet for the external index (extindex) at:
+; $base_url
+; See public-inbox-config(5)manpage for more details:
+; https://public-inbox.org/public-inbox-config.html
+[extindex "$name"]
+       topdir = /path/to/extindex-topdir
+       url = https://example.com/$name/
+       url = http://example.onion/$name/
+EOS
+       for my $k (qw(infourl)) {
+               defined(my $v = $ibx->{$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};
index 6f62b5a035be0cd040a78876f8609116e4d5d4a7..b9acc9793292b6d3b7a7189853c01b75af186279 100644 (file)
@@ -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);