Skip to content

fix multiple readme file rendering and fix #1657 #1658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions modules/markup/markup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 9 additions & 3 deletions routers/repo/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was in the TODO list. 😄

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. This PR will finish the TODO.

readmeFile = entry.Blob()
break
if tp != "" {
break
}
}

if readmeFile != nil {
Expand Down