unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
* Bug: wwwlisting doesn't get css styling
@ 2021-08-17 14:53 Konstantin Ryabitsev
  2021-08-18 11:41 ` [RFC] wwwlisting: support global CSS in HTML view Eric Wong
  0 siblings, 1 reply; 4+ messages in thread
From: Konstantin Ryabitsev @ 2021-08-17 14:53 UTC (permalink / raw)
  To: meta

Hello:

Just noticed that the wwwlisting page doesn't apply any css stylesheets
(currently still on https://x-lore.kernel.org/lists.html ). It should do the
same thing as any other page view, e.g. so it can properly respect the client
prefers-color-scheme choices.

-K

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [RFC] wwwlisting: support global CSS in HTML view
  2021-08-17 14:53 Bug: wwwlisting doesn't get css styling Konstantin Ryabitsev
@ 2021-08-18 11:41 ` Eric Wong
  2021-08-26 12:36   ` Eric Wong
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Wong @ 2021-08-18 11:41 UTC (permalink / raw)
  To: Konstantin Ryabitsev; +Cc: meta

Konstantin Ryabitsev <konstantin@linuxfoundation.org> wrote:
> Hello:
> 
> Just noticed that the wwwlisting page doesn't apply any css stylesheets
> (currently still on https://x-lore.kernel.org/lists.html ). It should do the
> same thing as any other page view, e.g. so it can properly respect the client
> prefers-color-scheme choices.

Ah, I intended /$INBOX/$FOO.css to be easily overridable on a
per-inbox basis so different inboxes could have different color
schemes for ease-of-identification.

Maybe "/+/" (as in "/+/$FOO.css") is a good URL path prefix...
----------8<--------
Subject: [PATCH] wwwlisting: support global CSS in HTML view

Since CSS can be overridden by a static webserver on a per-inbox
basis, we need a similar pattern to deal with the instance-wide
WwwListing HTML.  "/+/" probably won't conflict with any current
nor future public inbox names.

I don't think it'll cause problems with common linkifiers or URL
extractors, either (and it's unlikely anybody would want to
share URLs of just the CSS in a plain text(-like) format).
---
 lib/PublicInbox/WWW.pm        | 13 ++++++++-----
 lib/PublicInbox/WwwListing.pm |  6 +++---
 2 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/lib/PublicInbox/WWW.pm b/lib/PublicInbox/WWW.pm
index 841a7e85..1afdece0 100644
--- a/lib/PublicInbox/WWW.pm
+++ b/lib/PublicInbox/WWW.pm
@@ -133,7 +133,8 @@ sub call {
 	# convenience redirects order matters
 	} elsif ($path_info =~ m!$INBOX_RE/([^/]{2,})\z!o) {
 		r301($ctx, $1, $2);
-
+	} elsif ($path_info =~ m!\A/\+/([a-zA-Z0-9_\-\.]+)\.css\z!) {
+		get_css($ctx, undef, $1); # for WwwListing
 	} else {
 		legacy_redirects($ctx, $path_info);
 	}
@@ -627,18 +628,20 @@ sub style {
 	};
 }
 
-# /$INBOX/$KEY.css endpoint
+# /$INBOX/$KEY.css and /+/$KEY.css endpoints
 # CSS is configured globally for all inboxes, but we access them on
 # a per-inbox basis.  This allows administrators to setup per-inbox
 # static routes to intercept the request before it hits PSGI
+# inbox == undef => top-level WwwListing
 sub get_css ($$$) {
 	my ($ctx, $inbox, $key) = @_;
-	my $r404 = invalid_inbox($ctx, $inbox);
+	my $r404 = defined($inbox) ? invalid_inbox($ctx, $inbox) : undef;
 	return $r404 if $r404;
 	my $self = $ctx->{www};
-	my $css_map = $self->{-css_map} || stylesheets_prepare($self, '');
+	my $css_map = $self->{-css_map} ||
+		stylesheets_prepare($self, defined($inbox) ? '' : '+/');
 	my $css = $css_map->{$key};
-	if (!defined($css) && $key eq 'userContent') {
+	if (!defined($css) && defined($inbox) && $key eq 'userContent') {
 		my $env = $ctx->{env};
 		$css = PublicInbox::UserContent::sample($ctx->{ibx}, $env);
 	}
diff --git a/lib/PublicInbox/WwwListing.pm b/lib/PublicInbox/WwwListing.pm
index 98a69986..a31aa4ca 100644
--- a/lib/PublicInbox/WwwListing.pm
+++ b/lib/PublicInbox/WwwListing.pm
@@ -190,9 +190,9 @@ sub psgi_triple {
 	my $h = [ 'Content-Type', 'text/html; charset=UTF-8',
 			'Content-Length', undef ];
 	my $gzf = gzf_maybe($h, $ctx->{env});
-	$gzf->zmore('<html><head><title>' .
-				'public-inbox listing</title>' .
-				'</head><body>');
+	$gzf->zmore('<html><head><title>public-inbox listing</title>' .
+			$ctx->{www}->style('+/') .
+			'</head><body>');
 	my $code = 404;
 	if (my $list = delete $ctx->{-list}) {
 		my $mset = delete $ctx->{-mset};


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [RFC] wwwlisting: support global CSS in HTML view
  2021-08-18 11:41 ` [RFC] wwwlisting: support global CSS in HTML view Eric Wong
@ 2021-08-26 12:36   ` Eric Wong
  2021-08-26 13:51     ` Konstantin Ryabitsev
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Wong @ 2021-08-26 12:36 UTC (permalink / raw)
  To: Konstantin Ryabitsev; +Cc: meta

Eric Wong <e@80x24.org> wrote:
> Maybe "/+/" (as in "/+/$FOO.css") is a good URL path prefix...

Pushed as commit 26c635060dcae35feae836b02a18a6a11e408312

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RFC] wwwlisting: support global CSS in HTML view
  2021-08-26 12:36   ` Eric Wong
@ 2021-08-26 13:51     ` Konstantin Ryabitsev
  0 siblings, 0 replies; 4+ messages in thread
From: Konstantin Ryabitsev @ 2021-08-26 13:51 UTC (permalink / raw)
  To: Eric Wong; +Cc: meta

On Thu, Aug 26, 2021 at 12:36:06PM +0000, Eric Wong wrote:
> Eric Wong <e@80x24.org> wrote:
> > Maybe "/+/" (as in "/+/$FOO.css") is a good URL path prefix...
> 
> Pushed as commit 26c635060dcae35feae836b02a18a6a11e408312

It looks good to me, thanks!

-K

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-08-26 13:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-08-17 14:53 Bug: wwwlisting doesn't get css styling Konstantin Ryabitsev
2021-08-18 11:41 ` [RFC] wwwlisting: support global CSS in HTML view Eric Wong
2021-08-26 12:36   ` Eric Wong
2021-08-26 13:51     ` Konstantin Ryabitsev

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).