mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 16:11:08 +08:00
FEATURE: Remove user IDs from internal URLs. (#7406)
This commit is contained in:
@ -40,6 +40,7 @@ class CookedPostProcessor
|
||||
post_process_images
|
||||
post_process_quotes
|
||||
optimize_urls
|
||||
remove_user_ids
|
||||
update_post_image
|
||||
enforce_nofollow
|
||||
pull_hotlinked_images(bypass_bump)
|
||||
@ -595,6 +596,19 @@ class CookedPostProcessor
|
||||
end
|
||||
end
|
||||
|
||||
def remove_user_ids
|
||||
@doc.css("a[href]").each do |a|
|
||||
uri = URI(a["href"])
|
||||
next if uri.hostname != Discourse.current_hostname
|
||||
|
||||
query = Rack::Utils.parse_nested_query(uri.query)
|
||||
next if !query.delete("u")
|
||||
|
||||
uri.query = query.map { |k, v| "#{k}=#{v}" }.join("&").presence
|
||||
a["href"] = uri.to_s
|
||||
end
|
||||
end
|
||||
|
||||
def enforce_nofollow
|
||||
if !@cooking_options[:omit_nofollow] && SiteSetting.add_rel_nofollow_to_user_content
|
||||
PrettyText.add_rel_nofollow_to_user_content(@doc)
|
||||
|
Reference in New Issue
Block a user