* [PATCH] www_coderepo: serve CSS files per-repo
@ 2024-10-01 7:40 Eric Wong
0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2024-10-01 7:40 UTC (permalink / raw)
To: meta
For WWW admins configuring CSS via <link> or @import directives,
we need to ensure users can download per-repo CSS files via
$CODEREPO_NICK/$KEY.css
---
lib/PublicInbox/WWW.pm | 6 +++++-
lib/PublicInbox/WwwCoderepo.pm | 9 +++++++++
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/lib/PublicInbox/WWW.pm b/lib/PublicInbox/WWW.pm
index 4dfe83c1..420132d9 100644
--- a/lib/PublicInbox/WWW.pm
+++ b/lib/PublicInbox/WWW.pm
@@ -747,7 +747,11 @@ sub get_css ($$$) {
if (!defined($rec) && defined($inbox) && $key eq 'userContent') {
$rec = [ PublicInbox::UserContent::sample($ctx) ];
}
- $rec // return r404();
+ srv_css_rec($rec);
+}
+
+sub srv_css_rec { # $_[0] may be ctx->{www}
+ my $rec = $_[-1] // return r404();
my ($css, undef) = @$rec; # TODO: Last-Modified + If-Modified-Since
my $h = [ 'Content-Length', length($css), 'Content-Type', 'text/css' ];
PublicInbox::GitHTTPBackend::cache_one_year($h);
diff --git a/lib/PublicInbox/WwwCoderepo.pm b/lib/PublicInbox/WwwCoderepo.pm
index 5e086fee..413dfee5 100644
--- a/lib/PublicInbox/WwwCoderepo.pm
+++ b/lib/PublicInbox/WwwCoderepo.pm
@@ -322,6 +322,12 @@ sub refs_foo { # /$REPO/refs/{heads,tags} endpoints
$qsp->psgi_yield($ctx->{env}, undef, \&_refs_parse_hdr, $ctx);
}
+sub _get_css ($$) {
+ my ($ctx, $key) = @_;
+ $ctx->{www}->{-css_map} // $ctx->{www}->stylesheets_prepare('');
+ PublicInbox::WWW::srv_css_rec $ctx->{www}->{-css_map}->{$key};
+}
+
sub srv { # endpoint called by PublicInbox::WWW
my ($self, $ctx) = @_;
my $path_info = $ctx->{env}->{PATH_INFO};
@@ -357,6 +363,9 @@ 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/(.+?)/([a-zA-Z0-9_\-\.]+)\.css\z! &&
+ $pi_cfg->get_coderepo($1)) {
+ _get_css $ctx, $2;
} elsif ($path_info =~ m!\A/(.*?\*.*?)/*\z!) {
my $re = PublicInbox::Config::glob2re($1);
PublicInbox::RepoList::html($self, $ctx, qr!$re\z!) // r(404);
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2024-10-01 7:40 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-01 7:40 [PATCH] www_coderepo: serve CSS files per-repo 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).