- if (!$prevent_xss && -s "$projectroot/$project/README.html") {
- print "<div class=\"title\">readme</div>\n" .
- "<div class=\"readme\">\n";
- insert_file("$projectroot/$project/README.html");
- print "\n</div>\n"; # class="readme"
+ if (!$prevent_xss) {
+ open my $fd, "-|", git_cmd(), "ls-tree", "master", "--name-only"
+ or die_error(500, "Error checking ls_tree for readme");
+ my @readme_files = map { chomp; $_ } <$fd>;
+ close $fd
+ or die_error(500, "Error checking ls_tree for readme");
+ if (@readme_files) {
+ $hash_base ||= git_get_head_hash($project);
+ foreach my $readme_file (@readme_files) {
+ if ($readme_file =~ /^readme($|.+)/i && check_tree_filter($readme_file)) {
+ my $hash = git_get_hash_by_path($hash_base, $readme_file)
+ or die_error(500, "Error getting hash for readme file $readme_file");
+ print "<div class=\"title readme-title\">$readme_file<nav class=\"formats_nav\">";
+ print $cgi->a({-href => href(action=>"blob", hash=>$hash)}, "source") . " | ";
+ print $cgi->a({-href => href(action=>"blob_plain", hash=>$hash)}, "raw");
+ print "</nav>";
+ print "</div>\n" .
+ "<div class=\"readme\">\n";
+ open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash
+ or die_error(500, "Cat of readme '$hash' failed");
+ my $filecontents = "";
+ while (my $line = <$fd>) {
+ $filecontents .= $line;
+ }
+
+ # Process markdown if necessary
+ if ($readme_file =~ /\.md$/i && check_pandoc()) {
+ $filecontents = pandoc->parse('markdown' => $filecontents)->to_html;
+ }
+ print($filecontents);
+
+ close $fd
+ or die_error(500, "Error processing readme file $hash");
+ print "\n</div>\n"; # class="readme"
+ last;
+ }
+ }
+ }