fixed readme路径转换问题处理

This commit is contained in:
xxq250 2025-05-12 16:00:23 +08:00
parent 56212f4536
commit ab576fdba5
2 changed files with 4 additions and 2 deletions

View File

@ -161,6 +161,7 @@ module RepositoriesHelper
s_content = s_content.starts_with?("/") ? s_content[1..-1] : s_content[0..-1] s_content = s_content.starts_with?("/") ? s_content[1..-1] : s_content[0..-1]
s_content = File.expand_path(s_content, file_path) s_content = File.expand_path(s_content, file_path)
s_content = s_content.split("#{Rails.root}/")[1] s_content = s_content.split("#{Rails.root}/")[1]
next if s_content.blank?
# content = content.gsub(s[0], "/#{s_content}") # content = content.gsub(s[0], "/#{s_content}")
join_xxx = s_content.include?("?") ? "&" : "?" join_xxx = s_content.include?("?") ? "&" : "?"
s_content = [base_url, "/api/#{owner&.login}/#{repo.identifier}/raw/#{s_content}#{join_xxx}ref=#{ref}"].join s_content = [base_url, "/api/#{owner&.login}/#{repo.identifier}/raw/#{s_content}#{join_xxx}ref=#{ref}"].join
@ -190,6 +191,7 @@ module RepositoriesHelper
path = [owner&.login, repo&.identifier, 'tree', ref, file_path].join("/") path = [owner&.login, repo&.identifier, 'tree', ref, file_path].join("/")
s_content = File.expand_path(s_content, path) s_content = File.expand_path(s_content, path)
s_content = s_content.split("#{Rails.root}")[1] s_content = s_content.split("#{Rails.root}")[1]
next if s_content.blank?
case k.to_s case k.to_s
when 'ss_src' when 'ss_src'
content = content.gsub("src=\"#{s[0]}\"", "src=\"/#{s_content}\"") content = content.gsub("src=\"#{s[0]}\"", "src=\"/#{s_content}\"")
@ -202,7 +204,7 @@ module RepositoriesHelper
when 'ss_href_1' when 'ss_href_1'
content = content.gsub("href=\'#{s[0]}\'", "href=\'#{s_content}\'") content = content.gsub("href=\'#{s[0]}\'", "href=\'#{s_content}\'")
else else
content = content.gsub("(#{s[0]})", "(/#{s_content})") content = content.gsub("(#{s[0]})", "(#{s_content})")
end end
end end
rescue rescue

View File

@ -24,7 +24,7 @@
class CommitLog < ApplicationRecord class CommitLog < ApplicationRecord
belongs_to :user belongs_to :user
belongs_to :project belongs_to :project
belongs_to :repository # belongs_to :repository
has_many :project_trends, as: :trend, dependent: :destroy has_many :project_trends, as: :trend, dependent: :destroy