Browse Source

fix multiple readme file rendering and fix #1657 (#1658)

* fix multiple readme file rendering and fix #1657

* remove unnecessary loop
for-closed-social
Lunny Xiao 7 years ago
committed by Bo-Yi Wu
parent
commit
0d1e001b9c
2 changed files with 18 additions and 3 deletions
  1. +9
    -0
      modules/markup/markup.go
  2. +9
    -3
      routers/repo/view.go

+ 9
- 0
modules/markup/markup.go View File

@ -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 {

+ 9
- 3
routers/repo/view.go View File

@ -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 {

Loading…
Cancel
Save