mirror of
https://github.com/discourse/discourse.git
synced 2025-02-21 19:44:09 +08:00
FIX: Keep alt
and title
in lightbox when indexing for search.
Follow up to cfd507822f9330967f3ed9f970505e7f4896b523
This commit is contained in:
parent
e87ca59401
commit
2a69ab4a4c
@ -190,9 +190,25 @@ class SearchIndexer
|
|||||||
|
|
||||||
document = Nokogiri::HTML("<div>#{html}</div>", nil, Encoding::UTF_8.to_s)
|
document = Nokogiri::HTML("<div>#{html}</div>", nil, Encoding::UTF_8.to_s)
|
||||||
|
|
||||||
document.css(
|
nodes = document.css(
|
||||||
"div.#{CookedPostProcessor::LIGHTBOX_WRAPPER_CSS_CLASS}"
|
"div.#{CookedPostProcessor::LIGHTBOX_WRAPPER_CSS_CLASS}"
|
||||||
).remove
|
)
|
||||||
|
|
||||||
|
if nodes.present?
|
||||||
|
nodes.each do |node|
|
||||||
|
node.traverse do |child_node|
|
||||||
|
next if child_node == node
|
||||||
|
|
||||||
|
if %w{a img}.exclude?(child_node.name)
|
||||||
|
child_node.remove
|
||||||
|
elsif child_node.name == "a"
|
||||||
|
ATTRIBUTES.each do |attribute|
|
||||||
|
child_node.remove_attribute(attribute)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
document.css("a[href]").each do |node|
|
document.css("a[href]").each do |node|
|
||||||
node.remove_attribute("href") if node["href"] == node.text
|
node.remove_attribute("href") if node["href"] == node.text
|
||||||
|
@ -61,7 +61,7 @@ describe SearchIndexer do
|
|||||||
|
|
||||||
scrubbed = scrub(html)
|
scrubbed = scrub(html)
|
||||||
|
|
||||||
expect(scrubbed).to eq("Discourse 51%20PM")
|
expect(scrubbed).to eq("Discourse 51%20PM Untitled%20design%20(21)")
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'correctly indexes a post according to version' do
|
it 'correctly indexes a post according to version' do
|
||||||
@ -137,7 +137,7 @@ describe SearchIndexer do
|
|||||||
|
|
||||||
post = Fabricate(:post, raw: <<~RAW)
|
post = Fabricate(:post, raw: <<~RAW)
|
||||||
Let me see how I can fix this image
|
Let me see how I can fix this image
|
||||||
<img src="#{src}" width="2" height="2">
|
<img src="#{src}" title="GOT" alt="white walkers" width="2" height="2">
|
||||||
RAW
|
RAW
|
||||||
|
|
||||||
post.rebake!
|
post.rebake!
|
||||||
@ -149,7 +149,7 @@ describe SearchIndexer do
|
|||||||
)
|
)
|
||||||
|
|
||||||
expect(post.post_search_data.raw_data).to eq(
|
expect(post.post_search_data.raw_data).to eq(
|
||||||
"#{topic.title} #{topic.category.name} Let me see how I can fix this image"
|
"#{topic.title} #{topic.category.name} Let me see how I can fix this image white walkers GOT"
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user