Skip to content

Commit 0d1e001

Browse files
lunnyappleboy
authored andcommitted
fix multiple readme file rendering and fix #1657 (#1658)
* fix multiple readme file rendering and fix #1657 * remove unnecessary loop
1 parent 98548c8 commit 0d1e001

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

modules/markup/markup.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ func Type(filename string) string {
5959
return ""
6060
}
6161

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+
6271
// IsReadmeFile reports whether name looks like a README file
6372
// based on its name.
6473
func IsReadmeFile(name string) bool {

routers/repo/view.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,19 @@ func renderDirectory(ctx *context.Context, treeLink string) {
5656

5757
var readmeFile *git.Blob
5858
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 {
6065
continue
6166
}
6267

63-
// TODO: collect all possible README files and show with priority.
6468
readmeFile = entry.Blob()
65-
break
69+
if tp != "" {
70+
break
71+
}
6672
}
6773

6874
if readmeFile != nil {

0 commit comments

Comments
 (0)