| @@ -14,6 +14,12 @@ module RepositoriesHelper | |||||
| default_type.include?(str&.downcase) | default_type.include?(str&.downcase) | ||||
| end | end | ||||
| def is_readme_type?(str) | |||||
| return false if str.blank? | |||||
| readme_types = ["readme.md", "readme", "readme_en.md", "readme_zh.md", "readme_en", "readme_zh"] | |||||
| readme_types.include?(str.to_s.downcase) | |||||
| end | |||||
| def render_commit_author(author_json) | def render_commit_author(author_json) | ||||
| return nil if author_json.blank? | return nil if author_json.blank? | ||||
| find_user_by_login author_json['login'] | find_user_by_login author_json['login'] | ||||
| @@ -12,7 +12,7 @@ json.target entry['target'] | |||||
| json.download_url entry['download_url'] | json.download_url entry['download_url'] | ||||
| json.direct_download direct_download | json.direct_download direct_download | ||||
| json.image_type image_type | json.image_type image_type | ||||
| json.is_readme_file is_readme_type?(file_name) | |||||
| if entry['latest_commit'] | if entry['latest_commit'] | ||||
| json.partial! 'last_commit', entry: entry | json.partial! 'last_commit', entry: entry | ||||
| end | end | ||||
| @@ -18,12 +18,15 @@ json.entries do | |||||
| json.type entry['type'] | json.type entry['type'] | ||||
| json.size entry['size'] | json.size entry['size'] | ||||
| content = | content = | ||||
| if entry['name'] === 'README.md' | |||||
| if is_readme_type?(entry['name']) | |||||
| is_readme_file = true | |||||
| content = Gitea::Repository::Entries::GetService.call(@project_owner, @project.identifier, entry['name'], ref: @ref)['content'] | content = Gitea::Repository::Entries::GetService.call(@project_owner, @project.identifier, entry['name'], ref: @ref)['content'] | ||||
| readme_render_decode64_content(content, @path) | readme_render_decode64_content(content, @path) | ||||
| else | else | ||||
| is_readme_file = false | |||||
| entry['content'] | entry['content'] | ||||
| end | end | ||||
| json.is_readme_file is_readme_file | |||||
| json.content content | json.content content | ||||
| json.target entry['target'] | json.target entry['target'] | ||||
| if entry['latest_commit'] | if entry['latest_commit'] | ||||