Browse Source

fix multiple readme file rendering and fix #1657 (#1658)

* fix multiple readme file rendering and fix #1657

* remove unnecessary loop
Lunny Xiao 3 years ago
parent
commit
0d1e001b9c
2 changed files with 18 additions and 3 deletions
  1. 9 0
      modules/markup/markup.go
  2. 9 3
      routers/repo/view.go

+ 9 - 0
modules/markup/markup.go

@@ -59,6 +59,15 @@ func Type(filename string) string {
59 59
 	return ""
60 60
 }
61 61
 
62
+// ReadmeFileType reports whether name looks like a README file
63
+// based on its name and find the parser via its ext name
64
+func ReadmeFileType(name string) (string, bool) {
65
+	if IsReadmeFile(name) {
66
+		return Type(name), true
67
+	}
68
+	return "", false
69
+}
70
+
62 71
 // IsReadmeFile reports whether name looks like a README file
63 72
 // based on its name.
64 73
 func IsReadmeFile(name string) bool {

+ 9 - 3
routers/repo/view.go

@@ -56,13 +56,19 @@ func renderDirectory(ctx *context.Context, treeLink string) {
56 56
 
57 57
 	var readmeFile *git.Blob
58 58
 	for _, entry := range entries {
59
-		if entry.IsDir() || !markup.IsReadmeFile(entry.Name()) {
59
+		if entry.IsDir() {
60
+			continue
61
+		}
62
+
63
+		tp, ok := markup.ReadmeFileType(entry.Name())
64
+		if !ok {
60 65
 			continue
61 66
 		}
62 67
 
63
-		// TODO: collect all possible README files and show with priority.
64 68
 		readmeFile = entry.Blob()
65
-		break
69
+		if tp != "" {
70
+			break
71
+		}
66 72
 	}
67 73
 
68 74
 	if readmeFile != nil {