about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2023-11-28 14:56:27 +0000
committerEric Wong <e@80x24.org>2023-11-29 02:13:26 +0000
commita8e3c2ad544f9f78ebbe91bfe0dece0e2d385322 (patch)
tree7f304b6f51c9f5babfb2b687c4b6e128efb7dbec
parent83655d5dd1679e7c44586aaae4e16a2bffdeaa1a (diff)
downloadpublic-inbox-a8e3c2ad544f9f78ebbe91bfe0dece0e2d385322.tar.gz
The HTML is still extremely rough, but links seem to be mostly
working...
-rw-r--r--MANIFEST1
-rw-r--r--lib/PublicInbox/CodeSearch.pm8
-rw-r--r--lib/PublicInbox/RepoList.pm39
-rw-r--r--lib/PublicInbox/WwwCoderepo.pm3
-rw-r--r--lib/PublicInbox/WwwStream.pm11
-rw-r--r--lib/PublicInbox/WwwText.pm10
6 files changed, 61 insertions, 11 deletions
diff --git a/MANIFEST b/MANIFEST
index 7b6178f9..e22674b7 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -323,6 +323,7 @@ lib/PublicInbox/PktOp.pm
 lib/PublicInbox/Qspawn.pm
 lib/PublicInbox/Reply.pm
 lib/PublicInbox/RepoAtom.pm
+lib/PublicInbox/RepoList.pm
 lib/PublicInbox/RepoSnapshot.pm
 lib/PublicInbox/RepoTree.pm
 lib/PublicInbox/SHA.pm
diff --git a/lib/PublicInbox/CodeSearch.pm b/lib/PublicInbox/CodeSearch.pm
index 7d7f6df6..7c0dd063 100644
--- a/lib/PublicInbox/CodeSearch.pm
+++ b/lib/PublicInbox/CodeSearch.pm
@@ -341,4 +341,12 @@ EOM
         }
 }
 
+sub repos_sorted {
+        my $pi_cfg = shift;
+        my @recs = map { [ 0, $_ ] } @_; # PublicInbox::Git objects
+        my @todo = @recs;
+        $pi_cfg->each_cindex(\&load_commit_times, \@todo);
+        @recs = sort { $b->[0] <=> $a->[0] } @recs;
+}
+
 1;
diff --git a/lib/PublicInbox/RepoList.pm b/lib/PublicInbox/RepoList.pm
new file mode 100644
index 00000000..4b313ed6
--- /dev/null
+++ b/lib/PublicInbox/RepoList.pm
@@ -0,0 +1,39 @@
+# Copyright (C) all contributors <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+package PublicInbox::RepoList;
+use v5.12;
+use parent qw(PublicInbox::WwwStream);
+use PublicInbox::Hval qw(ascii_html prurl fmt_ts);
+require PublicInbox::CodeSearch;
+
+sub html_top_fallback { # WwwStream->html_repo_top
+        my ($ctx) = @_;
+        my $title = delete($ctx->{-title_html}) //
+                ascii_html("$ctx->{env}->{PATH_INFO}*");
+        my $upfx = $ctx->{-upfx} // '';
+        "<html><head><title>$title</title>" .
+                $ctx->{www}->style($upfx) . '</head><body>';
+}
+
+sub html ($$$) {
+        my ($wcr, $ctx, $pfx) = @_;
+        my $cr = $wcr->{pi_cfg}->{-coderepos};
+        my @nicks = grep(m!\A\Q$pfx\E/!, keys %$cr) or return; # 404
+        __PACKAGE__->html_init($ctx);
+        my $zfh = $ctx->zfh;
+        print $zfh "<pre>matching coderepos\n";
+        my @recs = PublicInbox::CodeSearch::repos_sorted($wcr->{pi_cfg},
+                                                        @$cr{@nicks});
+        my $env = $ctx->{env};
+        for (@recs) {
+                my ($t, $git) = @$_;
+                my $nick = ascii_html("$git->{nick}");
+                for my $u ($git->pub_urls($env)) {
+                        $u = prurl($env, $u);
+                        print $zfh "\n".fmt_ts($t).qq{ <a\nhref="$u">$nick</a>}
+                }
+        }
+        $ctx->html_done('</pre>');
+}
+
+1;
diff --git a/lib/PublicInbox/WwwCoderepo.pm b/lib/PublicInbox/WwwCoderepo.pm
index 8ab4911f..d1354af5 100644
--- a/lib/PublicInbox/WwwCoderepo.pm
+++ b/lib/PublicInbox/WwwCoderepo.pm
@@ -19,6 +19,7 @@ use PublicInbox::ViewDiff qw(uri_escape_path);
 use PublicInbox::RepoSnapshot;
 use PublicInbox::RepoAtom;
 use PublicInbox::RepoTree;
+use PublicInbox::RepoList;
 use PublicInbox::OnDestroy;
 use URI::Escape qw(uri_escape_utf8);
 use File::Spec;
@@ -354,6 +355,8 @@ sub srv { # endpoint called by PublicInbox::WWW
         } elsif ($path_info =~ m!\A/(.+?)/(refs/(?:heads|tags))/\z! and
                         ($ctx->{git} = $pi_cfg->get_coderepo($1))) {
                 refs_foo($self, $ctx, $2);
+        } elsif ($path_info =~ m!\A/(.+?)/\z!) {
+                PublicInbox::RepoList::html($self, $ctx, $1) // r(404);
         } elsif ($path_info =~ m!\A/(.+?)\z! and
                         ($git = $pi_cfg->get_coderepo($1))) {
                 my $qs = $ctx->{env}->{QUERY_STRING};
diff --git a/lib/PublicInbox/WwwStream.pm b/lib/PublicInbox/WwwStream.pm
index 3a1d6edf..8d32074f 100644
--- a/lib/PublicInbox/WwwStream.pm
+++ b/lib/PublicInbox/WwwStream.pm
@@ -17,8 +17,9 @@ http://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/public-inb
 https://public-inbox.org/public-inbox.git) ];
 
 sub base_url ($) {
-        my $ctx = shift;
-        my $base_url = ($ctx->{ibx} // $ctx->{git})->base_url($ctx->{env});
+        my ($ctx) = @_;
+        my $thing = $ctx->{ibx} // $ctx->{git} // return;
+        my $base_url = $thing->base_url($ctx->{env});
         chop $base_url; # no trailing slash for clone
         $base_url;
 }
@@ -40,7 +41,7 @@ sub async_eml { # for async_blob_cb
 
 sub html_repo_top ($) {
         my ($ctx) = @_;
-        my $git = $ctx->{git};
+        my $git = $ctx->{git} // return $ctx->html_top_fallback;
         my $desc = ascii_html($git->description);
         my $title = delete($ctx->{-title_html}) // $desc;
         my $upfx = $ctx->{-upfx} // '';
@@ -265,11 +266,11 @@ sub aresponse {
 }
 
 sub html_init {
-        my ($ctx) = @_;
+        my $ctx = $_[-1];
         $ctx->{base_url} = base_url($ctx);
         my $h = $ctx->{-res_hdr} = ['Content-Type', 'text/html; charset=UTF-8'];
         $ctx->{gz} = PublicInbox::GzipFilter::gz_or_noop($h, $ctx->{env});
-        bless $ctx, __PACKAGE__;
+        bless $ctx, @_ > 1 ? $_[0] : __PACKAGE__;
         print { $ctx->zfh } html_top($ctx);
 }
 
diff --git a/lib/PublicInbox/WwwText.pm b/lib/PublicInbox/WwwText.pm
index 4b4b2e4c..5e23005e 100644
--- a/lib/PublicInbox/WwwText.pm
+++ b/lib/PublicInbox/WwwText.pm
@@ -252,19 +252,17 @@ sub coderepos_raw ($$) {
         my $cr = $cfg->repo_objs($ctx->{ibx}) or return ();
         my $buf = 'Code repositories for project(s) associated with this '.
                 $ctx->{ibx}->thing_type . ":\n";
-        my @recs = map { [ 0, $_ ] } @$cr;
-        my @todo = @recs;
-        $cfg->each_cindex('load_commit_times', \@todo);
-        @recs = sort { $b->[0] <=> $a->[0] } @recs;
+        my @recs = PublicInbox::CodeSearch::repos_sorted($cfg, @$cr);
         my $cr_score = $ctx->{ibx}->{-cr_score};
+        my $env = $ctx->{env};
         for (@recs) {
                 my ($t, $git) = @$_;
-                for ($git->pub_urls($ctx->{env})) {
+                for ($git->pub_urls($env)) {
                         my $u = m!\A(?:[a-z\+]+:)?//!i ? $_ : $top_url.$_;
                         my $nr = $cr_score->{$git->{nick}};
                         $buf .= "\n";
                         $buf .= $nr ? sprintf('% 9u', $nr) : (' 'x9);
-                        $buf .= ' '.fmt_ts($t).' '.prurl($ctx->{env}, $u);
+                        $buf .= ' '.fmt_ts($t).' '.prurl($env, $u);
                 }
         }
         ($buf);