forked from Gitlink/forgeplus
commit
e1d7b0b881
|
@ -33,34 +33,38 @@ module RepositoriesHelper
|
|||
|
||||
def readme_render_decode64_content(str, path)
|
||||
return nil if str.blank?
|
||||
content = Base64.decode64(str).force_encoding('UTF-8')
|
||||
begin
|
||||
content = Base64.decode64(str).force_encoding('UTF-8')
|
||||
|
||||
c_regex = /\!\[.*?\]\((.*?)\)/
|
||||
src_regex = /src=\"(.*?)\"/
|
||||
ss = content.to_s.scan(c_regex)
|
||||
ss_src = content.to_s.scan(src_regex)
|
||||
total_images = ss + ss_src
|
||||
if total_images.length > 0
|
||||
total_images.each do |s|
|
||||
image_title = /\"(.*?)\"/
|
||||
r_content = s[0]
|
||||
remove_title = r_content.to_s.scan(image_title)
|
||||
if remove_title.length > 0
|
||||
r_content = r_content.gsub(/#{remove_title[0]}/, "").strip
|
||||
c_regex = /\!\[.*?\]\((.*?)\)/
|
||||
src_regex = /src=\"(.*?)\"/
|
||||
ss = content.to_s.scan(c_regex)
|
||||
ss_src = content.to_s.scan(src_regex)
|
||||
total_images = ss + ss_src
|
||||
if total_images.length > 0
|
||||
total_images.each do |s|
|
||||
image_title = /\"(.*?)\"/
|
||||
r_content = s[0]
|
||||
remove_title = r_content.to_s.scan(image_title)
|
||||
if remove_title.length > 0
|
||||
r_content = r_content.gsub(/#{remove_title[0]}/, "").strip
|
||||
end
|
||||
if r_content.include?("?")
|
||||
new_r_content = r_content + "&raw=true"
|
||||
else
|
||||
new_r_content = r_content + "?raw=true"
|
||||
end
|
||||
unless r_content.include?("http://") || r_content.include?("https://") || r_content.include?("mailto:")
|
||||
new_r_content = "#{path}" + new_r_content
|
||||
end
|
||||
content = content.gsub(/#{r_content}/, new_r_content)
|
||||
end
|
||||
if r_content.include?("?")
|
||||
new_r_content = r_content + "&raw=true"
|
||||
else
|
||||
new_r_content = r_content + "?raw=true"
|
||||
end
|
||||
unless r_content.include?("http://") || r_content.include?("https://") || r_content.include?("mailto:")
|
||||
new_r_content = "#{path}" + new_r_content
|
||||
end
|
||||
content = content.gsub(/#{r_content}/, new_r_content)
|
||||
end
|
||||
|
||||
return content
|
||||
rescue
|
||||
return str
|
||||
end
|
||||
|
||||
return content
|
||||
end
|
||||
|
||||
# unix_time values for example: 1604382982
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
json.content @project.content
|
||||
json.website @project.website
|
||||
if @result[:readme].blank?
|
||||
json.readme nil!
|
||||
json.readme nil
|
||||
else
|
||||
json.readme @result[:readme].merge(content: readme_render_decode64_content(@result[:readme]["content"], nil))
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue