# starts an HTML page for Repobrowse in a consistent way
sub html_start {
- my ($self, $req, $title_html) = @_;
+ my ($self, $req, $title_html, $opts) = @_;
my $desc = $req->{repo_info}->{desc_html};
+ my $meta;
+
+ if ($opts) {
+ my @robots;
+ foreach (qw(nofollow noindex)) {
+ push @robots, $_ if $opts->{$_};
+ }
+ $meta = qq(<meta\nname=robots\ncontent=") .
+ join(',', @robots) . '" />';
+ }
"<html><head><title>$title_html</title>" .
- PublicInbox::Hval::STYLE .
+ PublicInbox::Hval::STYLE . $meta .
"</head><body><pre><b>$desc</b>";
}
'%t', '%p', '%D', '%b%x00');
sub git_commit_stream {
- my ($req, $q, $H, $log, $fh) = @_;
+ my ($self, $req, $q, $H, $log, $fh) = @_;
chomp(my $h = <$log>); # abbreviated commit
my $l;
chomp(my $s = utf8_html($l = <$log>)); # subject
my $rel = $req->{relcmd};
my $qs = $q->qs(id => $h);
chomp $H;
- my $x = "<html><head><title>$s</title>" .
- PublicInbox::Hval::STYLE . '</head><body><pre>' .
- " commit $H (<a\nhref=\"${rel}patch$qs\">patch</a>)\n" .
- " tree <a\nhref=\"${rel}tree?id=$h\">$t</a>";
+ my $x = $self->html_start($req, $s) . "\n" .
+ qq( commit $H (<a\nhref="${rel}patch$qs">patch</a>)\n) .
+ qq( tree <a\nrel=nofollow\nhref="${rel}tree?id=$h">$t</a>);
# extra show path information, if any
my $extra = $req->{extra};
my $e = PublicInbox::Hval->utf8($_, join('/', @t));
$ep = $e->as_path;
my $eh = $e->as_html;
- "<a\nhref=\"${rel}tree/$ep?id=$h\">$eh</a>";
+ $ep = "${rel}tree/$ep?id=$h";
+ qq(<a\nrel=nofollow\nhref="$ep">$eh</a>);
} @$extra);
$path = "/$ep";
}
sub {
my ($res) = @_; # Plack callback
my $fh = $res->([200, ['Content-Type'=>'text/html']]);
- git_commit_stream($req, $q, $H, $log, $fh);
+ git_commit_stream($self, $req, $q, $H, $log, $fh);
$fh->close;
}
}
$rv .= $ca;
} else {
my $p = $diff->{p}->[0];
- $rv .= "<a\nhref=\"${rel}tree/$diff->{path_a}?id=$p#n$na\">";
+ $rv .= qq(<a\nrel=nofollow);
+ $rv .= qq(\nhref="${rel}tree/$diff->{path_a}?id=$p#n$na">);
$rv .= "$ca</a>";
}
$rv .= ' ';
$rv .= $cb;
} else {
my $h = $diff->{h};
- $rv .= "<a\nhref=\"${rel}tree/$diff->{path_b}?id=$h#n$nb\">";
+ $rv .= qq(<a\nrel=nofollow);
+ $rv .= qq(\nhref="${rel}tree/$diff->{path_b}?id=$h#n$nb">);
$rv .= "<b>$cb</b></a>";
}
$rv . ' @@' . utf8_html($ctx);
$rv .= " <b>$last</b>";
} else {
my $h = $diff->{h};
- $rv .= " <a\nhref=\"${rel}tree/$path?id=$h#n$n\">";
+ $rv .= qq( <a\nrel=nofollow);
+ $rv .= qq(\nhref="${rel}tree/$path?id=$h#n$n">);
$rv .= "<b>$last</b></a>";
}
$rv .= " $at" . utf8_html($ctx);
my $p = PublicInbox::Hval->utf8(git_unquote($fn));
$p = $p->as_path;
$fn = utf8_html($fn);
- $s .= qq(\t<a\nid="$anchor"\nhref="${rel}tree/$p$qs">);
+ $s .= qq(\t<a\nrel=nofollow);
+ $s .= qq(\nid="$anchor"\nhref="${rel}tree/$p$qs">);
$s .= "$fn</a>\n";
}
$fh->write($s);
}
my $fh = $res->([200, ['Content-Type'=>'text/html; charset=UTF-8']]);
- $fh->write('<html><head>'. PublicInbox::Hval::STYLE .
- '<title></title></head><body>');
+ my $opts = { nofollow => 1 };
+ my $title = $req->{expath};
+ $title = $title eq '' ? 'tree' : utf8_html($title);
if ($type eq 'tree') {
+ $opts->{noindex} = 1;
+ $fh->write($self->html_start($req, $title, $opts) . "\n");
git_tree_show($req, $fh, $git, $hex, $q);
} elsif ($type eq 'blob') {
+ $fh->write($self->html_start($req, $title, $opts) . "\n");
git_blob_show($req, $fh, $git, $hex, $q);
} else {
# TODO
my $plain = join('/', "${rel}plain", @{$req->{extra}});
$plain = PublicInbox::Hval->utf8($plain)->as_path . $q->qs;
my $t = cur_path($req, $q);
- my $h = qq{<pre>path: $t\n\nblob $hex};
+ my $h = qq{\npath: $t\n\nblob $hex};
my $end = '';
$git->cat_file($hex, sub {
sub git_tree_show {
my ($req, $fh, $git, $hex, $q) = @_;
- $fh->write('<pre>');
my $ls = $git->popen(qw(ls-tree -l -z), $git->abbrev, $hex);
my $t = cur_path($req, $q);
my $pfx;
- $fh->write("path: $t\n\n");
+ $fh->write("\npath: $t\n\n");
my $qs = $q->qs;
if ($req->{tslash}) {