Skip to content

Commit 8a83d2b

Browse files
committed
prioritize readme.md
1 parent 31aa00f commit 8a83d2b

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

modules/markup/markup.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,11 @@ func IsMarkupFile(name, markup string) bool {
112112

113113
// IsReadmeFile reports whether name looks like a README file
114114
// based on its name.
115-
func IsReadmeFile(name string) bool {
115+
func IsReadmeFile(name string, strict bool) bool {
116116
name = strings.ToLower(name)
117+
if strict {
118+
return name == "readme.md"
119+
}
117120
if len(name) < 6 {
118121
return false
119122
} else if len(name) == 6 {

modules/markup/markup_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ func TestMisc_IsReadmeFile(t *testing.T) {
3232
}
3333

3434
for _, testCase := range trueTestCases {
35-
assert.True(t, IsReadmeFile(testCase))
35+
assert.True(t, IsReadmeFile(testCase, false))
3636
}
3737
for _, testCase := range falseTestCases {
38-
assert.False(t, IsReadmeFile(testCase))
38+
assert.False(t, IsReadmeFile(testCase, false))
3939
}
4040
}

routers/repo/view.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ func renderDirectory(ctx *context.Context, treeLink string) {
6262
continue
6363
}
6464

65-
if !markup.IsReadmeFile(entry.Name()) {
66-
continue
65+
if markup.IsReadmeFile(entry.Name(), true) {
66+
readmeFile = entry.Blob()
67+
break
6768
}
6869

69-
readmeFile = entry.Blob()
70-
if markup.Type(entry.Name()) != "" {
71-
break
70+
if markup.IsReadmeFile(entry.Name(), false) {
71+
readmeFile = entry.Blob()
7272
}
7373
}
7474

@@ -207,7 +207,7 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
207207
d, _ := ioutil.ReadAll(dataRc)
208208
buf = templates.ToUTF8WithFallback(append(buf, d...))
209209

210-
readmeExist := markup.IsReadmeFile(blob.Name())
210+
readmeExist := markup.IsReadmeFile(blob.Name(), false)
211211
ctx.Data["ReadmeExist"] = readmeExist
212212
if markup.Type(blob.Name()) != "" {
213213
ctx.Data["IsMarkup"] = true

0 commit comments

Comments
 (0)