aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2017-05-02 16:57:54 +0800
committerBo-Yi Wu <appleboy.tw@gmail.com>2017-05-02 16:57:54 +0800
commit0d1e001b9cae08c2d5f0ffc0ef9fec0f92d1683e (patch)
tree7859dedd67c1848060c03ef3fdbdcdb76aa2070b
parent98548c83d369a15f10dcd01656474c8dad98ba6a (diff)
downloadgitea-0d1e001b9cae08c2d5f0ffc0ef9fec0f92d1683e.tar.gz
gitea-0d1e001b9cae08c2d5f0ffc0ef9fec0f92d1683e.zip
fix multiple readme file rendering and fix #1657 (#1658)
* fix multiple readme file rendering and fix #1657 * remove unnecessary loop
-rw-r--r--modules/markup/markup.go9
-rw-r--r--routers/repo/view.go12
2 files changed, 18 insertions, 3 deletions
diff --git a/modules/markup/markup.go b/modules/markup/markup.go
index 0847fcfb0d..dc27997e8d 100644
--- a/modules/markup/markup.go
+++ b/modules/markup/markup.go
@@ -59,6 +59,15 @@ func Type(filename string) string {
return ""
}
+// ReadmeFileType reports whether name looks like a README file
+// based on its name and find the parser via its ext name
+func ReadmeFileType(name string) (string, bool) {
+ if IsReadmeFile(name) {
+ return Type(name), true
+ }
+ return "", false
+}
+
// IsReadmeFile reports whether name looks like a README file
// based on its name.
func IsReadmeFile(name string) bool {
diff --git a/routers/repo/view.go b/routers/repo/view.go
index 2e4b2644cd..165284a599 100644
--- a/routers/repo/view.go
+++ b/routers/repo/view.go
@@ -56,13 +56,19 @@ func renderDirectory(ctx *context.Context, treeLink string) {
var readmeFile *git.Blob
for _, entry := range entries {
- if entry.IsDir() || !markup.IsReadmeFile(entry.Name()) {
+ if entry.IsDir() {
+ continue
+ }
+
+ tp, ok := markup.ReadmeFileType(entry.Name())
+ if !ok {
continue
}
- // TODO: collect all possible README files and show with priority.
readmeFile = entry.Blob()
- break
+ if tp != "" {
+ break
+ }
}
if readmeFile != nil {