Skip to content

Commit

Permalink
prioritize readme.md
Browse files Browse the repository at this point in the history
  • Loading branch information
wewark committed Jan 10, 2019
1 parent 31aa00f commit 8a83d2b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
5 changes: 4 additions & 1 deletion modules/markup/markup.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,11 @@ func IsMarkupFile(name, markup string) bool {

// IsReadmeFile reports whether name looks like a README file
// based on its name.
func IsReadmeFile(name string) bool {
func IsReadmeFile(name string, strict bool) bool {
name = strings.ToLower(name)
if strict {
return name == "readme.md"
}
if len(name) < 6 {
return false
} else if len(name) == 6 {
Expand Down
4 changes: 2 additions & 2 deletions modules/markup/markup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ func TestMisc_IsReadmeFile(t *testing.T) {
}

for _, testCase := range trueTestCases {
assert.True(t, IsReadmeFile(testCase))
assert.True(t, IsReadmeFile(testCase, false))
}
for _, testCase := range falseTestCases {
assert.False(t, IsReadmeFile(testCase))
assert.False(t, IsReadmeFile(testCase, false))
}
}
12 changes: 6 additions & 6 deletions routers/repo/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ func renderDirectory(ctx *context.Context, treeLink string) {
continue
}

if !markup.IsReadmeFile(entry.Name()) {
continue
if markup.IsReadmeFile(entry.Name(), true) {
readmeFile = entry.Blob()
break
}

readmeFile = entry.Blob()
if markup.Type(entry.Name()) != "" {
break
if markup.IsReadmeFile(entry.Name(), false) {
readmeFile = entry.Blob()
}
}

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

readmeExist := markup.IsReadmeFile(blob.Name())
readmeExist := markup.IsReadmeFile(blob.Name(), false)
ctx.Data["ReadmeExist"] = readmeExist
if markup.Type(blob.Name()) != "" {
ctx.Data["IsMarkup"] = true
Expand Down

0 comments on commit 8a83d2b

Please sign in to comment.