From 8a83d2b1579c9a19d799ea1d6c2f02a24f8d3383 Mon Sep 17 00:00:00 2001 From: Khaled Hamed Date: Thu, 10 Jan 2019 19:32:59 +0200 Subject: [PATCH] prioritize readme.md --- modules/markup/markup.go | 5 ++++- modules/markup/markup_test.go | 4 ++-- routers/repo/view.go | 12 ++++++------ 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/modules/markup/markup.go b/modules/markup/markup.go index d17270fb011f6..3a90d3e93a983 100644 --- a/modules/markup/markup.go +++ b/modules/markup/markup.go @@ -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 { diff --git a/modules/markup/markup_test.go b/modules/markup/markup_test.go index b0ebfae57d725..85b060119571e 100644 --- a/modules/markup/markup_test.go +++ b/modules/markup/markup_test.go @@ -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)) } } diff --git a/routers/repo/view.go b/routers/repo/view.go index 78a305aa28aa3..abad65aa45bc0 100644 --- a/routers/repo/view.go +++ b/routers/repo/view.go @@ -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() } } @@ -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