FEATURE: Remove user IDs from internal URLs. (#7406)

This commit is contained in:
Dan Ungureanu
2019-04-23 05:45:41 +03:00
committed by Sam
parent e0e12c63e8
commit b706a1b08d
2 changed files with 38 additions and 0 deletions

View File

@ -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)