Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
Admin
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
osuny
Admin
Commits
ac72eeac
Unverified
Commit
ac72eeac
authored
3 years ago
by
Sébastien Gaya
Browse files
Options
Downloads
Patches
Plain Diff
replace links wp-uploads
parent
353f9108
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/models/communication/website/imported/with_rich_text.rb
+11
-5
11 additions, 5 deletions
app/models/communication/website/imported/with_rich_text.rb
app/views/active_storage/blobs/_blob.html.erb
+15
-5
15 additions, 5 deletions
app/views/active_storage/blobs/_blob.html.erb
with
26 additions
and
10 deletions
app/models/communication/website/imported/with_rich_text.rb
+
11
−
5
View file @
ac72eeac
...
...
@@ -5,16 +5,22 @@ module Communication::Website::Imported::WithRichText
def rich_text_with_attachments(text)
fragment = Nokogiri::HTML.fragment(text)
images = fragment.css("img[src*=\"#{website.website.uploads_url}\"]")
images.each do |image|
fragment = replace_tags_with_attachments(fragment, 'a', 'href')
fragment = replace_tags_with_attachments(fragment, 'img', 'src')
fragment.to_html
end
def replace_tags_with_attachments(fragment, tag_name, attribute_name)
nodes = fragment.css("#{tag_name}[#{attribute_name}*=\"#{website.website.uploads_url}\"]")
nodes.each do |node|
begin
url =
imag
e.attr(
'src'
)
url =
nod
e.attr(
attribute_name
)
blob = load_blob_from_url(url)
imag
e.replace ActionText::Attachment.from_attachable(blob).node.to_s
nod
e.replace ActionText::Attachment.from_attachable(blob).node.to_s
rescue
end
end
fragment
.to_html
fragment
end
def load_blob_from_url(url)
...
...
This diff is collapsed.
Click to expand it.
app/views/active_storage/blobs/_blob.html.erb
+
15
−
5
View file @
ac72eeac
<figure
class=
"attachment attachment--
<%=
blob
.representable? ? "preview" : "file"
%>
attachment--
<%=
blob.filename.extension
%>
"
>
<%
if blob.
representabl
e?
%>
<%
if blob.
imag
e?
%>
<%=
image_tag blob.representation(resize_to_limit: local_assigns[:in_gallery] ? [ 800, 600 ] : [ 1024, 768 ])
%>
<%
elsif blob.video?
%>
<video>
<source
src=
"
<%=
rails_blob_path(blob)
%>
"
type=
"
<%=
blob.content_type
%>
"
>
</video>
<%
else
%>
<p>
<span
class=
"attachment__name"
>
<%=
blob.filename
%>
</span>
<span
class=
"attachment__size"
>
<%=
number_to_human_size blob.byte_size
%>
</span>
</p>
<%=
link_to blob, target: :blank do
%>
<%
if blob.representable?
%>
<%=
image_tag blob.representation(resize_to_limit: local_assigns[:in_gallery] ? [ 800, 600 ] : [ 1024, 768 ])
%>
<%
else
%>
<p>
<span
class=
"attachment__name"
>
<%=
blob.filename
%>
</span>
<span
class=
"attachment__size"
>
<%=
number_to_human_size blob.byte_size
%>
</span>
</p>
<%
end
%>
<%
end
%>
<%
end
%>
<%
if caption = blob.try(:caption)
%>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment