* [PATCH 0/3] www: cleanup URL generation around coderepos @ 2023-01-04 10:34 Eric Wong 2023-01-04 10:34 ` [PATCH 1/3] git: fix non-empty SCRIPT_NAME handling for PSGI mounts Eric Wong ` (2 more replies) 0 siblings, 3 replies; 5+ messages in thread From: Eric Wong @ 2023-01-04 10:34 UTC (permalink / raw) To: meta This fixes coderepo URL generation and gives reasonable defaults based on the project.list nickname. It also accounts properly for `mount' directives in the PSGI file using Plack::App::URLMap to give an entire instance a URL prefix (as I do with yhbt.net/lore) Eric Wong (3): git: fix non-empty SCRIPT_NAME handling for PSGI mounts git: pub_urls shows base_url default www: make coderepo URL generation more consistent lib/PublicInbox/Git.pm | 9 +++++---- lib/PublicInbox/WwwStream.pm | 18 ++++++++---------- lib/PublicInbox/WwwText.pm | 20 +++++++------------- 3 files changed, 20 insertions(+), 27 deletions(-) ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/3] git: fix non-empty SCRIPT_NAME handling for PSGI mounts 2023-01-04 10:34 [PATCH 0/3] www: cleanup URL generation around coderepos Eric Wong @ 2023-01-04 10:34 ` Eric Wong 2023-01-04 10:34 ` [PATCH 2/3] git: pub_urls shows base_url default Eric Wong 2023-01-04 10:34 ` [PATCH 3/3] www: make coderepo URL generation more consistent Eric Wong 2 siblings, 0 replies; 5+ messages in thread From: Eric Wong @ 2023-01-04 10:34 UTC (permalink / raw) To: meta When using the `mount' directive in PSGI (Plack::App::URLMap), SCRIPT_NAME still needs to use a trailing slash before it can be joined with another URL. --- lib/PublicInbox/Git.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm index a1af776b..68f72052 100644 --- a/lib/PublicInbox/Git.pm +++ b/lib/PublicInbox/Git.pm @@ -461,10 +461,10 @@ sub local_nick ($) { sub host_prefix_url ($$) { my ($env, $url) = @_; return $url if index($url, '//') >= 0; - my $scheme = $env->{'psgi.url_scheme'}; my $host_port = $env->{HTTP_HOST} // "$env->{SERVER_NAME}:$env->{SERVER_PORT}"; - "$scheme://$host_port". ($env->{SCRIPT_NAME} || '/') . $url; + my $sn = $env->{SCRIPT_NAME} // ''; + "$env->{'psgi.url_scheme'}://$host_port$sn/$url"; } sub base_url { # for coderepos, PSGI-only ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/3] git: pub_urls shows base_url default 2023-01-04 10:34 [PATCH 0/3] www: cleanup URL generation around coderepos Eric Wong 2023-01-04 10:34 ` [PATCH 1/3] git: fix non-empty SCRIPT_NAME handling for PSGI mounts Eric Wong @ 2023-01-04 10:34 ` Eric Wong 2023-01-05 9:58 ` Eric Wong 2023-01-04 10:34 ` [PATCH 3/3] www: make coderepo URL generation more consistent Eric Wong 2 siblings, 1 reply; 5+ messages in thread From: Eric Wong @ 2023-01-04 10:34 UTC (permalink / raw) To: meta Since we have native coderepo viewing support without cgit, configuring coderepo.$FOO.cgitUrl shouldn't be necessary anymore and we can infer the public name based on the project nickname (or whatever's in the generated project.list) --- lib/PublicInbox/Git.pm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm index 68f72052..f6abe185 100644 --- a/lib/PublicInbox/Git.pm +++ b/lib/PublicInbox/Git.pm @@ -480,9 +480,10 @@ sub isrch {} # TODO sub pub_urls { my ($self, $env) = @_; if (my $urls = $self->{cgit_url}) { - return map { host_prefix_url($env, $_) } @$urls; + map { host_prefix_url($env, $_) } @$urls; + } else { + (base_url($self, $env)); } - (local_nick($self) // '???'); } sub cat_async_begin { ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 2/3] git: pub_urls shows base_url default 2023-01-04 10:34 ` [PATCH 2/3] git: pub_urls shows base_url default Eric Wong @ 2023-01-05 9:58 ` Eric Wong 0 siblings, 0 replies; 5+ messages in thread From: Eric Wong @ 2023-01-05 9:58 UTC (permalink / raw) To: meta Eric Wong <e@80x24.org> wrote: > Since we have native coderepo viewing support without cgit, > configuring coderepo.$FOO.cgitUrl shouldn't be necessary anymore > and we can infer the public name based on the project nickname > (or whatever's in the generated project.list) > --- > lib/PublicInbox/Git.pm | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm > index 68f72052..f6abe185 100644 > --- a/lib/PublicInbox/Git.pm > +++ b/lib/PublicInbox/Git.pm > @@ -480,9 +480,10 @@ sub isrch {} # TODO > sub pub_urls { > my ($self, $env) = @_; > if (my $urls = $self->{cgit_url}) { > - return map { host_prefix_url($env, $_) } @$urls; > + map { host_prefix_url($env, $_) } @$urls; > + } else { > + (base_url($self, $env)); > } > - (local_nick($self) // '???'); > } > > sub cat_async_begin { Erm, $git->{nick} isn't guaranteed to exist, actually. Perhaps it should and the code shouldn't have to guard against it, but there's cases where we need this and I'll squash it in: diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm index dff5813f..96627daa 100644 --- a/lib/PublicInbox/Git.pm +++ b/lib/PublicInbox/Git.pm @@ -485,10 +485,11 @@ sub host_prefix_url ($$) { sub base_url { # for coderepos, PSGI-only my ($self, $env) = @_; # env - PSGI env + my $nick = $self->{nick} // return undef; my $url = host_prefix_url($env, ''); # for mount in Plack::Builder $url .= '/' if substr($url, -1, 1) ne '/'; - $url . $self->{nick} . '/'; + $url . $nick . '/'; } sub isrch {} # TODO @@ -498,7 +499,7 @@ sub pub_urls { if (my $urls = $self->{cgit_url}) { map { host_prefix_url($env, $_) } @$urls; } else { - (base_url($self, $env)); + (base_url($self, $env) // '???'); } } ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/3] www: make coderepo URL generation more consistent 2023-01-04 10:34 [PATCH 0/3] www: cleanup URL generation around coderepos Eric Wong 2023-01-04 10:34 ` [PATCH 1/3] git: fix non-empty SCRIPT_NAME handling for PSGI mounts Eric Wong 2023-01-04 10:34 ` [PATCH 2/3] git: pub_urls shows base_url default Eric Wong @ 2023-01-04 10:34 ` Eric Wong 2 siblings, 0 replies; 5+ messages in thread From: Eric Wong @ 2023-01-04 10:34 UTC (permalink / raw) To: meta WwwStream and WwwText basically show the same thing, except the latter relies on Linkify to create links. --- lib/PublicInbox/WwwStream.pm | 18 ++++++++---------- lib/PublicInbox/WwwText.pm | 20 +++++++------------- 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/lib/PublicInbox/WwwStream.pm b/lib/PublicInbox/WwwStream.pm index f5b4df9f..59edad5d 100644 --- a/lib/PublicInbox/WwwStream.pm +++ b/lib/PublicInbox/WwwStream.pm @@ -90,24 +90,22 @@ sub coderepos ($) { my ($ctx) = @_; $ctx->{ibx} // return inboxes($ctx); my $cr = $ctx->{ibx}->{coderepo} // return (); - my $cfg = $ctx->{www}->{pi_cfg}; my $upfx = ($ctx->{-upfx} // ''). '../'; my $pfx = $ctx->{base_url} //= $ctx->base_url; my $up = $upfx =~ tr!/!/!; $pfx =~ s!/[^/]+\z!/! for (1..$up); - my @ret = ('<a id=code>' . + $pfx .= '/' if substr($pfx, -1, 1) ne '/'; + my $buf = '<a id=code>' . 'Code repositories for project(s) associated with this '. - $ctx->{ibx}->thing_type . "\n"); - my $objs = $cfg->repo_objs($ctx->{ibx}); - for my $git (@$objs) { - my @urls = $git->pub_urls($ctx->{env}); - for (@urls) { - my $u = m!\A(?:[a-z\+]+:)?//! ? $_ : $pfx.$_; + $ctx->{ibx}->thing_type . "\n"; + for my $git (@{$ctx->{www}->{pi_cfg}->repo_objs($ctx->{ibx})}) { + for ($git->pub_urls($ctx->{env})) { + my $u = m!\A(?:[a-z\+]+:)?//!i ? $_ : $pfx.$_; $u = ascii_html(prurl($ctx->{env}, $u)); - $ret[0] .= qq(\n\t<a\nhref="$u">$u</a>); + $buf .= qq(\n\t<a\nhref="$u">$u</a>); } } - @ret; # may be empty, this sub is called as an arg for join() + ($buf); } sub _html_end { diff --git a/lib/PublicInbox/WwwText.pm b/lib/PublicInbox/WwwText.pm index 224fed5c..c31a7f86 100644 --- a/lib/PublicInbox/WwwText.pm +++ b/lib/PublicInbox/WwwText.pm @@ -250,21 +250,15 @@ sub coderepos_raw ($$) { my ($ctx, $top_url) = @_; my $cr = $ctx->{ibx}->{coderepo} // return (); my $cfg = $ctx->{www}->{pi_cfg}; - my @ret = ('Code repositories for project(s) associated with this '. - $ctx->{ibx}->thing_type . "\n"); - for my $cr_name (@$cr) { - my $urls = $cfg->get_all("coderepo.$cr_name.cgiturl"); - if ($urls) { - for (@$urls) { - my $u = m!\A(?:[a-z\+]+:)?//!i ? $_ : - $top_url.$_; - $ret[0] .= "\n\t" . prurl($ctx->{env}, $u); - } - } else { - $ret[0] .= qq[\n\t$cr_name.git (no URL configured)]; + my $buf = 'Code repositories for project(s) associated with this '. + $ctx->{ibx}->thing_type . "\n"; + for my $git (@{$ctx->{www}->{pi_cfg}->repo_objs($ctx->{ibx})}) { + for ($git->pub_urls($ctx->{env})) { + my $u = m!\A(?:[a-z\+]+:)?//!i ? $_ : $top_url.$_; + $buf .= "\n\t" . prurl($ctx->{env}, $u); } } - @ret; # may be empty, this sub is called as an arg for join() + ($buf); } sub _add_non_http_urls ($$) { ^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-01-05 9:58 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2023-01-04 10:34 [PATCH 0/3] www: cleanup URL generation around coderepos Eric Wong 2023-01-04 10:34 ` [PATCH 1/3] git: fix non-empty SCRIPT_NAME handling for PSGI mounts Eric Wong 2023-01-04 10:34 ` [PATCH 2/3] git: pub_urls shows base_url default Eric Wong 2023-01-05 9:58 ` Eric Wong 2023-01-04 10:34 ` [PATCH 3/3] www: make coderepo URL generation more consistent Eric Wong
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).