Validate README format before displaying
Take the first previewable README file as project’s README, otherwise if none file is available, or we can’t preview any of them, we assume that project doesn’t have a README file.
This commit is contained in:
parent
2459d51633
commit
6ce01ca3ec
1 changed files with 7 additions and 9 deletions
|
@ -17,17 +17,15 @@ class Tree
|
|||
def readme
|
||||
return @readme if defined?(@readme)
|
||||
|
||||
available_readmes = blobs.select(&:readme?)
|
||||
|
||||
if available_readmes.count == 0
|
||||
return @readme = nil
|
||||
# Take the first previewable readme, or return nil if none is available or
|
||||
# we can't preview any of them
|
||||
readme_tree = blobs.find do |blob|
|
||||
blob.readme? && (previewable?(blob.name) || plain?(blob.name))
|
||||
end
|
||||
|
||||
# Take the first previewable readme, or the first available readme, if we
|
||||
# can't preview any of them
|
||||
readme_tree = available_readmes.find do |readme|
|
||||
previewable?(readme.name)
|
||||
end || available_readmes.first
|
||||
if readme_tree.nil?
|
||||
return @readme = nil
|
||||
end
|
||||
|
||||
readme_path = path == '/' ? readme_tree.name : File.join(path, readme_tree.name)
|
||||
|
||||
|
|
Loading…
Reference in a new issue