Added feature to gitweb tree mode: In current directory, display README if available.
authorAaron Taylor <ataylor@subgeniuskitty.com>
Thu, 5 Nov 2020 09:43:59 +0000 (09:43 +0000)
committerAaron Taylor <ataylor@subgeniuskitty.com>
Thu, 5 Nov 2020 09:43:59 +0000 (09:43 +0000)
gitweb.cgi
static/gitweb.css

index 6ee17d5..a3b31ce 100755 (executable)
@@ -3846,6 +3846,37 @@ sub insert_file {
        close $fd;
 }
 
        close $fd;
 }
 
+sub insert_html_file {
+       my $file_name = shift;
+       insert_file($file_name);
+}
+
+sub insert_text_file {
+       my $file_name = shift;
+
+       open my $fd, $file_name or die_error(500, "Couldn't open $file_name");
+
+       print "<pre>";
+       while (my $line = <$fd>) {
+               print to_utf8($line);
+       }
+       print "</pre>";
+}
+
+sub insert_markdown_file {
+       my $file_name = shift;
+
+       # TODO: Make this a config option?
+       my $markdown_cmd = "/usr/bin/markdown";
+
+       open my $fd, quote_command($markdown_cmd, $file_name)." |"
+               or die_error(500, "Couldn't open $file_name");
+
+       while (my $line = <$fd>) {
+               print to_utf8($line);
+       }
+}
+
 ## ......................................................................
 ## mimetype related functions
 
 ## ......................................................................
 ## mimetype related functions
 
@@ -7196,7 +7227,7 @@ sub git_tree {
                }
                git_print_page_nav('tree','', $hash_base, undef, undef,
                                   join(' | ', @views_nav));
                }
                git_print_page_nav('tree','', $hash_base, undef, undef,
                                   join(' | ', @views_nav));
-               git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash_base);
+               #git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash_base);
        } else {
                undef $hash_base;
                print "<div class=\"page_nav\">\n";
        } else {
                undef $hash_base;
                print "<div class=\"page_nav\">\n";
@@ -7255,6 +7286,30 @@ sub git_tree {
        }
        print "</table>\n" .
              "</div>";
        }
        print "</table>\n" .
              "</div>";
+
+       # If present, print one of the following, in order:
+       #       README.md, README.txt, README, README.html.
+       my $cwd_path = "$projectroot/$project";
+       $cwd_path =~ s/\.git$//;
+       $cwd_path = $cwd_path . $basedir;
+       if (!$prevent_xss && -s $cwd_path . "README.md") {
+               print "<div class=\"readme\">\n";
+               insert_markdown_file($cwd_path . "README.md");
+               print "\n</div>\n"; # class="readme"
+       } elsif (!$prevent_xss && -s $cwd_path . "README.txt") {
+               print "<div class=\"readme\">\n";
+               insert_text_file($cwd_path . "README.txt");
+               print "\n</div>\n"; # class="readme"
+       } elsif (!$prevent_xss && -s $cwd_path . "README") {
+               print "<div class=\"readme\">\n";
+               insert_text_file($cwd_path . "README");
+               print "\n</div>\n"; # class="readme"
+       } elsif (!$prevent_xss && -s $cwd_path . "README.html") {
+               print "<div class=\"readme\">\n";
+               insert_html_file($cwd_path . "README.html");
+               print "\n</div>\n"; # class="readme"
+       }
+
        git_footer_html();
 }
 
        git_footer_html();
 }
 
index a82f2e2..9295eb2 100644 (file)
@@ -332,7 +332,7 @@ th .header {
   box-sizing: border-box;
   margin: 0 auto 15px auto;
   padding: 15px;
   box-sizing: border-box;
   margin: 0 auto 15px auto;
   padding: 15px;
-  width: 95%;
+  width: 768px;
 }
 
 .readme h1 {
 }
 
 .readme h1 {