Skip to content

Commit ffe499e

Browse files
committed
Fix and improve external_filter
1 parent 38e2b10 commit ffe499e

File tree

3 files changed

+6
-14
lines changed

3 files changed

+6
-14
lines changed

assets/javascripts/lib/page.coffee

+5-1
Original file line numberDiff line numberDiff line change
@@ -178,16 +178,20 @@ onclick = (event) ->
178178
link = $.eventTarget(event)
179179
link = link.parentNode while link and link.tagName isnt 'A'
180180

181-
if link and not link.target and isSameOrigin(link.href)
181+
if link and not link.target and isSameOrigin(link.href) and not isSameOriginDifferentDoc
182182
event.preventDefault()
183183
path = link.pathname + link.search + link.hash
184184
path = path.replace /^\/\/+/, '/' # IE11 bug
185185
page.show(path)
186+
186187
return
187188

188189
isSameOrigin = (url) ->
189190
url.indexOf("#{location.protocol}//#{location.hostname}") is 0
190191

192+
isSameOriginDifferentDoc = (url) ->
193+
url.pathname == location.pathname
194+
191195
updateCanonicalLink = ->
192196
@canonicalLink ||= document.head.querySelector('link[rel="canonical"]')
193197
@canonicalLink.setAttribute('href', "https://#{location.host}#{location.pathname}")

lib/docs/core/filter.rb

-10
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,5 @@ def clean_path(path)
9696
path = path.gsub %r{\+}, '_plus_'
9797
path
9898
end
99-
100-
def path_to_root
101-
if subpath == ''
102-
return '../'
103-
else
104-
previous_dirs = subpath.scan(/\//)
105-
return '../' * previous_dirs.length
106-
end
107-
end
108-
10999
end
110100
end

lib/docs/filters/core/external_urls.rb

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ class ExternalUrlsFilter < Filter
66
def call
77
if context[:external_urls]
88

9-
root = path_to_root
10-
119
css('a').each do |node|
1210

1311
next unless anchorUrl = node['href']
@@ -24,7 +22,7 @@ def call
2422

2523
context[:external_urls].each do |host, name|
2624
if url.host.to_s.match?(host)
27-
node['href'] = root + name + url.path.to_s + '#' + url.fragment.to_s
25+
node['href'] = '/' + name + url.path.to_s + '#' + url.fragment.to_s
2826
end
2927
end
3028

0 commit comments

Comments
 (0)