Skip to content

Commit

Permalink
Fix titelize keeping newlines. Remove another tracking param. Remove …
Browse files Browse the repository at this point in the history
…&& in middle of url.
  • Loading branch information
stefansundin committed Aug 5, 2017
1 parent c6cccd9 commit c0bc3ac
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions config/initializers/05-string.rb
Expand Up @@ -21,7 +21,7 @@ def to_filename
end

def titelize
self.gsub(String::URL_REGEXP) do |url|
self.gsub("\n", " ").gsub(String::URL_REGEXP) do |url|
dest = url.resolve_url
"[#{dest.short_host}]"
end
Expand Down Expand Up @@ -153,13 +153,15 @@ def resolve_url(force=false)
# https://aws.amazon.com/podcasts/aws-podcast/?utm_content=bufferf4ae0&utm_medium=social&utm_source=twitter.com&utm_campaign=buffer
# https://aws.amazon.com/about-aws/whats-new/2016/09/aws-config-console-now-displays-api-events-associated-with-configuration-changes/?sc_channel=sm&sc_campaign=launch_Config_ead85f34&sc_publisher=tw_go&sc_content=AWS_Config_add_support_for_viewing_CloudTrail_API_events_from_Config_console&sc_geo=globaly
# https://aws.amazon.com/summits/washington-dc/?trkCampaign=DCSummit2017&trk=sm_twitter&adbsc=social_20170427_71906466&adbid=z123jzf53ojbjbm0l221ez2jtoeqijchx04&adbpl=gp&adbpr=100017971115449920316
dest = dest.gsub(/(?<=[?&])(?:(?:utm|sc)[_\-][a-z]+|utm|adb(?:sc|id|pr|pl)|trk(?:Campaign)?|mkt_tok|campaign-id|aff)=[^&#]+/, "")
dest = dest.gsub(/(?<=[?&])(?:(?:utm|sc)[_\-][a-z]+|utm|adb(?:sc|id|pr|pl)|trk(?:Campaign)?|mkt_tok|campaign-id|aff|linkId)=[^&#]+/, "")
# Remove #_=_
dest = dest.gsub(/#_=_$/, "")
# Remove #. tracking codes
dest = dest.gsub(/#\..*$/, "")
# Remove unnecessary ampersands (possibly caused by the above)
dest = dest.gsub(/(\?.+)&&+/, "\\1&")
while dest[/(\?.+?)&&+/]
dest = dest.gsub(/(\?.+?)&&+/, "\\1&")
end
dest = dest.gsub(/\?&+/, "?")
# Remove trailing ?&#
dest = dest.gsub(/[?&#]+(?:$|(?=#))/, "")
Expand Down

0 comments on commit c0bc3ac

Please sign in to comment.