diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index 19ef7f9de..2b6d9d405 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -14,6 +14,12 @@ module RepositoriesHelper default_type.include?(str&.downcase) 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) return nil if author_json.blank? find_user_by_login author_json['login'] diff --git a/app/views/repositories/_simple_entry.json.jbuilder b/app/views/repositories/_simple_entry.json.jbuilder index cdea42c8b..4890f4047 100644 --- a/app/views/repositories/_simple_entry.json.jbuilder +++ b/app/views/repositories/_simple_entry.json.jbuilder @@ -12,7 +12,7 @@ json.target entry['target'] json.download_url entry['download_url'] json.direct_download direct_download json.image_type image_type - +json.is_readme_file is_readme_type?(file_name) if entry['latest_commit'] json.partial! 'last_commit', entry: entry end diff --git a/app/views/repositories/entries.json.jbuilder b/app/views/repositories/entries.json.jbuilder index 7c7b5ef70..7b2c7c6e6 100644 --- a/app/views/repositories/entries.json.jbuilder +++ b/app/views/repositories/entries.json.jbuilder @@ -18,12 +18,15 @@ json.entries do json.type entry['type'] json.size entry['size'] 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'] readme_render_decode64_content(content, @path) else + is_readme_file = false entry['content'] end + json.is_readme_file is_readme_file json.content content json.target entry['target'] if entry['latest_commit']