summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorKhaled Hamed <khaled.hamedt@gmail.com>2019-01-14 21:15:06 +0200
committertechknowlogick <hello@techknowlogick.com>2019-01-14 14:15:06 -0500
commitbd759652965078c0cd5b948c94345ce5b73fd0d1 (patch)
tree9a3ecf0f7aaa13db0b87169c3dad077647e564b0 /routers
parent6868378673f5bb21eac54719d719557b32448db6 (diff)
downloadgitea-bd759652965078c0cd5b948c94345ce5b73fd0d1.tar.gz
gitea-bd759652965078c0cd5b948c94345ce5b73fd0d1.zip
Prioritize "readme.md" (#5691)
* prioritize readme.md * Improve IsReadmeFile * Add more tests
Diffstat (limited to 'routers')
-rw-r--r--routers/repo/view.go23
1 files changed, 18 insertions, 5 deletions
diff --git a/routers/repo/view.go b/routers/repo/view.go
index 78a305aa28..8739c139d9 100644
--- a/routers/repo/view.go
+++ b/routers/repo/view.go
@@ -56,18 +56,31 @@ func renderDirectory(ctx *context.Context, treeLink string) {
return
}
- var readmeFile *git.Blob
+ // 3 for the extensions in exts[] in order
+ // the last one is for a readme that doesn't
+ // strictly match an extension
+ var readmeFiles [4]*git.Blob
+ var exts = []string{".md", ".txt", ""} // sorted by priority
for _, entry := range entries {
if entry.IsDir() {
continue
}
- if !markup.IsReadmeFile(entry.Name()) {
- continue
+ for i, ext := range exts {
+ if markup.IsReadmeFile(entry.Name(), ext) {
+ readmeFiles[i] = entry.Blob()
+ }
}
- readmeFile = entry.Blob()
- if markup.Type(entry.Name()) != "" {
+ if markup.IsReadmeFile(entry.Name()) {
+ readmeFiles[3] = entry.Blob()
+ }
+ }
+
+ var readmeFile *git.Blob
+ for _, f := range readmeFiles {
+ if f != nil {
+ readmeFile = f
break
}
}