From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 1/2] www_listing: show ->ALL at top of HTML listing
Date: Fri, 27 Aug 2021 12:08:44 +0000 [thread overview]
Message-ID: <20210827120845.29682-2-e@80x24.org> (raw)
In-Reply-To: <20210827120845.29682-1-e@80x24.org>
It's a special case and we can show it in the HTML display
without affecting manifest.js.gz generation.
---
lib/PublicInbox/WwwListing.pm | 45 ++++++++++++++++++++++-------------
t/extindex-psgi.t | 6 +++++
2 files changed, 34 insertions(+), 17 deletions(-)
diff --git a/lib/PublicInbox/WwwListing.pm b/lib/PublicInbox/WwwListing.pm
index 8b54d724..eabda98a 100644
--- a/lib/PublicInbox/WwwListing.pm
+++ b/lib/PublicInbox/WwwListing.pm
@@ -7,22 +7,29 @@ package PublicInbox::WwwListing;
use strict;
use v5.10.1;
use PublicInbox::Hval qw(prurl fmt_ts ascii_html);
-use PublicInbox::Linkify;
use PublicInbox::GzipFilter qw(gzf_maybe);
use PublicInbox::ConfigIter;
use PublicInbox::WwwStream;
+use URI::Escape qw(uri_escape_utf8);
sub ibx_entry {
my ($ctx, $ibx, $ce) = @_;
- $ce->{description} //= $ibx->description;
+ my $desc = ascii_html($ce->{description} //= $ibx->description);
my $ts = fmt_ts($ce->{-modified} //= $ibx->modified);
- my $url = prurl($ctx->{env}, $ibx->{url});
- my $tmp = <<"";
-* $ts - $url
- $ce->{description}
-
- if (defined(my $info_url = $ibx->{infourl})) {
- $tmp .= ' ' . prurl($ctx->{env}, $info_url) . "\n";
+ my ($url, $href);
+ if (defined($ibx->{url})) {
+ $url = $href = ascii_html(prurl($ctx->{env}, $ibx->{url}));
+ } else {
+ $href = ascii_html(uri_escape_utf8($ibx->{name})) . '/';
+ $url = ascii_html($ibx->{name});
+ }
+ my $tmp = <<EOM;
+* $ts - <a\nhref="$href">$url</a>
+ $desc
+EOM
+ if (defined($url = $ibx->{infourl})) {
+ $url = ascii_html(prurl($ctx->{env}, $url));
+ $tmp .= qq( <a\nhref="$url">$url</a>\n);
}
push(@{$ctx->{-list}}, (scalar(@_) == 3 ? # $misc in use, already sorted
$tmp : [ $ce->{-modified}, $tmp ] ));
@@ -86,19 +93,24 @@ sub add_misc_ibx { # MiscSearch->retry_reopen callback
limit => $q->{l}
};
$qs .= ' type:inbox';
- if (my $user_query = $q->{'q'}) {
+
+ delete $ctx->{-list}; # reset if retried
+ my $pi_cfg = $ctx->{www}->{pi_cfg};
+ if (defined(my $user_query = $q->{'q'})) {
$qs = "( $qs ) AND ( $user_query )";
+ } else { # special case for ALL
+ $ctx->ibx_entry($pi_cfg->ALL // die('BUG: ->ALL expected'), {});
}
my $mset = $misc->mset($qs, $opt); # sorts by $MODIFIED (mtime)
- delete $ctx->{-list}; # reset if retried
- my $pi_cfg = $ctx->{www}->{pi_cfg};
+ 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}->{$ctx->hide_key};
- grep(/$re/, @{$ibx->{url}}) or next;
+ next if $ibx->{-hide}->{$hide_key};
+ grep(/$re/, @{$ibx->{url} // []}) or next;
$ctx->ibx_entry($ibx, $misc->doc2ibx_cache_ent($doc));
if ($r) { # for descriptions in search_nav_bot
my $pct = PublicInbox::Search::get_pct($mi);
@@ -203,9 +215,8 @@ sub psgi_triple {
@$list = map { $_->[1] }
sort { $b->[0] <=> $a->[0] } @$list;
}
- $list = join("\n", @$list);
- my $l = PublicInbox::Linkify->new;
- $gzf->zmore('<pre>'.$l->to_html($list));
+ $gzf->zmore('<pre>');
+ $gzf->zmore(join("\n", @$list));
$gzf->zmore(mset_footer($ctx, $mset)) if $mset;
} else {
$gzf->zmore('<pre>no inboxes, yet');
diff --git a/t/extindex-psgi.t b/t/extindex-psgi.t
index d4761641..31b04acd 100644
--- a/t/extindex-psgi.t
+++ b/t/extindex-psgi.t
@@ -28,6 +28,8 @@ run_script([qw(-extindex --all), "$tmpdir/eidx"], $env) or BAIL_OUT;
[extindex "all"]
topdir = $tmpdir/eidx
url = http://bogus.example.com/all
+[publicinbox]
+ wwwlisting = all
EOM
}
my $www = PublicInbox::WWW->new(PublicInbox::Config->new($pi_config));
@@ -55,6 +57,10 @@ my $client = sub {
$res = $cb->(GET('/all/all.mbox.gz'));
is($res->code, 200, 'all.mbox.gz');
+
+ $res = $cb->(GET('/'));
+ my $html = $res->content;
+ like($html, qr!\Qhttp://bogus.example.com/all\E!, 'html shows /all');
};
test_psgi(sub { $www->call(@_) }, $client);
%$env = (%$env, TMPDIR => $tmpdir, PI_CONFIG => $pi_config);
next prev parent reply other threads:[~2021-08-27 12:08 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-26 17:01 Add a way to search all from wwwlisting Konstantin Ryabitsev
2021-08-27 12:08 ` [PATCH 0/2] wwwlisting shows /all/ Eric Wong
2021-08-27 12:08 ` Eric Wong [this message]
2021-08-27 12:08 ` [PATCH 2/2] www_listing: fix odd "locate inbox" cases Eric Wong
2021-08-27 13:03 ` [PATCH 0/2] wwwlisting shows /all/ Konstantin Ryabitsev
2021-08-27 14:33 ` Konstantin Ryabitsev
2021-08-27 22:03 ` [PATCH] www: avoid potential auto-vivification on ibx->{url} Eric Wong
2021-08-28 18:00 ` Konstantin Ryabitsev
2021-08-27 21:15 ` [PATCH 0/2] wwwlisting shows /all/ Eric Wong
2021-09-26 1:30 ` [PATCH] www_listing: support /all/ search as a 302 redirect Eric Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210827120845.29682-2-e@80x24.org \
--to=e@80x24.org \
--cc=meta@public-inbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).