user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* [PATCH] www: allow including links to NNTP sites in HTML footer
@ 2016-08-12 20:45  7% Eric Wong
  0 siblings, 0 replies; 1+ results
From: Eric Wong @ 2016-08-12 20:45 UTC (permalink / raw)
  To: meta

Improve the discoverability of NNTP endpoints for users
who still know what NNTP is.

==> ~/.public-inbox/config <==
; aliases for the locally-run nntpd can be specified in
; the "publicinbox" section:
[publicinbox]
	nntpserver = nntp://ou63pmih66umazou.onion/
	nntpserver = news.public-inbox.org

	; NNTPS is not supported natively, yet,
	; but one can use haproxy or similar
	; nntpserver = nntps://news.public-inbox.invalid/

; mirrors for specific inboxes may be specified either as full
; NNTP (or NNTPS) URLs, or with the server name only if the
; newsgroup name is specfied for a local NNTP server
[publicinbox "git"]
	...
	newsgroup = inbox.a.b.c
	nntpmirror = nntp://czquwvybam4bgbro.onion/
	nntpmirror = hjrcffqmbrq6wope.onion

	; there may be a mirror on a different server with a
	; different name:
	nntpmirror = nntp://news.example.com/differently.named.group

; (And I really need to write manpages for all this...)
---
 lib/PublicInbox/Config.pm    |  5 ++++-
 lib/PublicInbox/Inbox.pm     | 46 ++++++++++++++++++++++++++++++++++++++++++++
 lib/PublicInbox/WwwStream.pm | 11 ++++++++---
 t/view.t                     |  1 +
 4 files changed, 59 insertions(+), 4 deletions(-)

diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm
index 5eae1f1..5adcd0c 100644
--- a/lib/PublicInbox/Config.pm
+++ b/lib/PublicInbox/Config.pm
@@ -145,7 +145,10 @@ sub _fill {
 		my $v = $self->{"$pfx.$k"};
 		$rv->{$k} = $v if defined $v;
 	}
-	foreach my $k (qw(altid)) { # TODO: more arrays
+
+	# TODO: more arrays, we should support multi-value for
+	# more things to encourage decentralization
+	foreach my $k (qw(altid nntpmirror)) {
 		if (defined(my $v = $self->{"$pfx.$k"})) {
 			$rv->{$k} = ref($v) eq 'ARRAY' ? $v : [ $v ];
 		}
diff --git a/lib/PublicInbox/Inbox.pm b/lib/PublicInbox/Inbox.pm
index 922ca9b..414973c 100644
--- a/lib/PublicInbox/Inbox.pm
+++ b/lib/PublicInbox/Inbox.pm
@@ -147,6 +147,52 @@ sub base_url {
 	}
 }
 
+sub nntp_url {
+	my ($self) = @_;
+	$self->{-nntp_url} ||= do {
+		# no checking for nntp_usable here, we can point entirely
+		# to non-local servers or users run by a different user
+		my $ns = $self->{-pi_config}->{'publicinbox.nntpserver'};
+		my $group = $self->{newsgroup};
+		my @urls;
+		if ($ns && $group) {
+			$ns = [ $ns ] if ref($ns) ne 'ARRAY';
+			@urls = map {
+				my $u = m!\Anntps?://! ? $_ : "nntp://$_";
+				$u .= '/' if $u !~ m!/\z!;
+				$u.$group;
+			} @$ns;
+		}
+
+		my $mirrors = $self->{nntpmirror};
+		if ($mirrors) {
+			my @m;
+			foreach (@$mirrors) {
+				my $u = m!\Anntps?://! ? $_ : "nntp://$_";
+				if ($u =~ m!\Anntps?://[^/]+/?\z!) {
+					if ($group) {
+						$u .= '/' if $u !~ m!/\z!;
+						$u .= $group;
+					} else {
+						warn
+"publicinbox.$self->{name}.nntpmirror=$_ missing newsgroup name\n";
+					}
+				}
+				# else: allow full URLs like:
+				# nntp://news.example.com/alt.example
+				push @m, $u;
+			}
+			my %seen = map { $_ => 1 } @urls;
+			foreach my $u (@m) {
+				next if $seen{$u};
+				$seen{$u} = 1;
+				push @urls, $u;
+			}
+		}
+		\@urls;
+	};
+}
+
 sub nntp_usable {
 	my ($self) = @_;
 	my $ret = $self->mm && $self->search;
diff --git a/lib/PublicInbox/WwwStream.pm b/lib/PublicInbox/WwwStream.pm
index 29395f4..9ed25e1 100644
--- a/lib/PublicInbox/WwwStream.pm
+++ b/lib/PublicInbox/WwwStream.pm
@@ -72,10 +72,8 @@ sub _html_end {
 	chop $http;
 	my %seen = ( $http => 1 );
 	my @urls = ($http);
-	my $need_tor;
 	foreach my $u (@{$obj->cloneurl}) {
 		next if $seen{$u};
-		$need_tor = 1 if $u =~ m!\A[^:]+://\w+\.onion/!;
 		$seen{$u} = 1;
 		push @urls, $u =~ /\Ahttps?:/ ? qq(<a\nhref="$u">$u</a>) : $u;
 	}
@@ -86,7 +84,14 @@ sub _html_end {
 			join("\n", map { "\tgit clone --mirror $_" } @urls);
 	}
 
-	if ($need_tor) {
+	my @nntp = map { qq(<a\nhref="$_">$_</a>) } @{$obj->nntp_url};
+	if (@nntp) {
+		$urls .= "\n\n";
+		$urls .= @nntp == 1 ? 'Newsgroup' : 'Newsgroups are';
+		$urls .= ' available over NNTP:';
+		$urls .= "\n\t" . join("\n\t", @nntp) . "\n";
+	}
+	if ($urls =~ m!\b[^:]+://\w+\.onion/!) {
 		$urls .= "\n note: .onion URLs require Tor: ";
 		$urls .= qq[<a\nhref="$TOR_URL">$TOR_URL</a>];
 	}
diff --git a/t/view.t b/t/view.t
index 4cee439..46fbe41 100644
--- a/t/view.t
+++ b/t/view.t
@@ -27,6 +27,7 @@ my $ctx = {
 		search => sub { undef },
 		base_url => sub { 'http://example.com/' },
 		cloneurl => sub {[]},
+		nntp_url => sub {[]},
 		description => sub { '' }),
 };
 $ctx->{-inbox}->{-primary_address} = 'test@example.com';
-- 
EW


^ permalink raw reply related	[relevance 7%]

Results 1-1 of 1 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2016-08-12 20:45  7% [PATCH] www: allow including links to NNTP sites in HTML footer Eric Wong

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