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.
parent 2459d516
...@@ -17,18 +17,16 @@ class Tree ...@@ -17,18 +17,16 @@ class Tree
def readme def readme
return @readme if defined?(@readme) return @readme if defined?(@readme)
available_readmes = blobs.select(&:readme?) # 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
if available_readmes.count == 0 if readme_tree.nil?
return @readme = nil return @readme = nil
end 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
readme_path = path == '/' ? readme_tree.name : File.join(path, readme_tree.name) readme_path = path == '/' ? readme_tree.name : File.join(path, readme_tree.name)
git_repo = repository.raw_repository git_repo = repository.raw_repository
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment