git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] opml output for gitweb
@ 2005-06-13 22:53 Erik van Konijnenburg
  0 siblings, 0 replies; only message in thread
From: Erik van Konijnenburg @ 2005-06-13 22:53 UTC (permalink / raw)
  To: Kay Sievers; +Cc: Git Mailing List

Gitweb currently has a nice orange thingy at the footer of
every page, except for the title page.

The attached patch addresses that lacuna with an OPML link,
a file format to import and export RSS collections from
feed readers.  Using this link, you can subscribe to all
RSS feeds on a git site in one go.

The patch was prepared against ftp://ehlo.org/gitweb2.cgi
and manually edited to undo localisation to my test tree.
It's only lightly tested: exporting a feed collection from
gitweb and importing it in Sage and liferea seems to work.

Regards,
Erik

Signed-off-by: Erik van Konijnenburg <ekonijn@xs4all.nl>

--- /home/konijn/gitweb2.cgi	2005-06-13 21:58:39.000000000 +0200
+++ gitweb.cgi	2005-06-14 00:31:24.000000000 +0200
@@ -50,6 +50,9 @@
 	if ($action eq "git-logo.png") {
 		git_logo();
 		exit;
+	} elsif ($action eq "opml") {
+		git_opml();
+		exit;
 	}
 } else {
 	$action = "summary";
@@ -243,7 +246,8 @@
 div.diff_info { font-family:monospace; color:#000099; background-color:#edece6; font-style:italic; }
 div.index_include { border:solid #d9d8d1; border-width:0px 0px 1px; padding:12px 8px; }
 div.search { margin:4px 8px; position:absolute; top:56px; right:12px }
-a.rss_logo { float:right; padding:3px 0px; width:35px; line-height:10px;
+a.rss_logo {
+	float:right; padding:3px 0px; width:35px; line-height:10px;
 	border:1px solid; border-color:#fcc7a5 #7d3302 #3e1a01 #ff954e;
 	color:#ffffff; background-color:#ff6600;
 	font-weight:bold; font-family:sans-serif; font-size:10px;
@@ -289,6 +293,9 @@
 		}
 		print $cgi->a({-href => "$my_uri?p=$project;a=rss", -class => "rss_logo"}, "RSS") . "\n";
 	}
+	else {
+		print $cgi->a({-href => "$my_uri?a=opml", -class => "rss_logo"}, "OPML") . "\n";
+	}
 	print "</div>\n" .
 	      "</body>\n" .
 	      "</html>";
@@ -1197,6 +1204,83 @@
 	git_footer_html();
 }
 
+sub git_opml {
+	my @list;
+	if (-d $projects_list) {
+		# search in directory
+		my $dir = $projects_list;
+		opendir my $dh, $dir or return undef;
+		while (my $dir = readdir($dh)) {
+			if (-e "$projectroot/$dir/HEAD") {
+				my $pr = {
+					path => $dir,
+				};
+				push @list, $pr
+			}
+		}
+		closedir($dh);
+	} elsif (-f $projects_list) {
+		# read from file(url-encoded):
+		# 'git%2Fgit.git Linus+Torvalds'
+		# 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin'
+		# 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman'
+		open my $fd , $projects_list or return undef;
+		while (my $line = <$fd>) {
+			chomp $line;
+			my ($path, $owner) = split ' ', $line;
+			$path = unescape($path);
+			$owner = unescape($owner);
+			if (!defined $path) {
+				next;
+			}
+			if (-e "$projectroot/$path/HEAD") {
+				my $pr = {
+					path => $path,
+					owner => $owner,
+				};
+				push @list, $pr
+			}
+		}
+		close $fd;
+	}
+
+	if (!@list) {
+		die_error(undef, "No project found.");
+	}
+	@list = sort {$a->{'path'} cmp $b->{'path'}} @list;
+
+
+	print $cgi->header(-type => 'text/xml', -charset => 'utf-8');
+	print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".
+	      "<opml version=\"1.0\">\n".
+	      "<head>".
+	      "  <title>Git OPML Export</title>\n".
+	      "</head>\n".
+	      "<body>\n".
+	      "  <outline text=\"Git RSS Feeds\">\n";
+
+	foreach my $pr (@list) {
+		my %proj = %$pr;
+		my $head = git_read_hash("$proj{'path'}/HEAD");
+		if (!defined $head) {
+			next;
+		}
+		$ENV{'GIT_OBJECT_DIRECTORY'} = "$projectroot/$proj{'path'}/objects";
+		my %co = git_read_commit($head);
+		if (!%co) {
+			next;
+		}
+
+		my $path = escapeHTML(chop_str($proj{'path'}, 25, 5));
+		my $rss =  "$my_url?p=$proj{'path'};a=rss";
+		my $html =  "$my_url?p=$proj{'path'};a=log";
+		print "<outline type=\"rss\" text=\"$path\" title=\"$path\" xmlUrl=\"$rss\" htmlUrl=\"$html\"/>\n";
+	}
+	print "  </outline>\n".
+	      "</body>\n".
+	      "</opml>\n";
+}
+
 sub git_rss {
 	# http://www.notestips.com/80256B3A007F2692/1/NAMO5P9UPQ
 	open my $fd, "-|", "$gitbin/git-rev-list --max-count=20 " . git_read_hash("$project/HEAD") or die_error(undef, "Open failed.");

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2005-06-13 22:53 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-06-13 22:53 [PATCH] opml output for gitweb Erik van Konijnenburg

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 NNTP newsgroup(s).