Skip to content

Commit

Permalink
Remove domain and protocol from links pointing back to the site.
Browse files Browse the repository at this point in the history
This avoids having links in the various user-generated contents pointing
to the other version of the website, hence causing a protocol switch to
the visitor.

https://linuxfr.org/suivi/gestion-des-liens-vers-http-s-linuxfr-org
  • Loading branch information
nud authored and nono committed Feb 11, 2012
1 parent 9e5be3b commit bfbe66d
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/lfmarkdown.rb
Expand Up @@ -36,6 +36,7 @@ def to_html
process_internal_wiki_links
process_wikipedia_links
ret = fix_heading_levels(super)
ret = fix_internal_links(ret)
ret = process_code(ret)
ret = add_toc_content(ret) if text.length > 5_000
ret
Expand Down Expand Up @@ -63,6 +64,11 @@ def fix_heading_levels(str)
str
end

def fix_internal_links(str)
str.gsub!(/(href|src)="https?:\/\/#{MY_DOMAIN}\//) { |_| "#{$1}=\"/" }
str
end

# Code taken from gollum (http://github.com/github/gollum)
def extract_code
@text.gsub!(/^``` ?(.+?)\r?\n(.+?)\r?\n```\r?$/m) do
Expand Down

0 comments on commit bfbe66d

Please sign in to comment.