Fix and improve external_filter

pull/1495/head
Enoc 4 years ago
parent 38e2b107a2
commit 843e2c7bd2

@ -178,16 +178,22 @@ onclick = (event) ->
link = $.eventTarget(event)
link = link.parentNode while link and link.tagName isnt 'A'
if link and not link.target and isSameOrigin(link.href)
if link and not link.target and isSameOrigin(link.href) and isSameOriginDifferentDoc(link)
event.preventDefault()
path = link.pathname + link.search + link.hash
path = path.replace /^\/\/+/, '/' # IE11 bug
page.show(path)
return
isSameOrigin = (url) ->
url.indexOf("#{location.protocol}//#{location.hostname}") is 0
isSameOriginDifferentDoc = (url) ->
console.log(url.pathname)
console.log(location.pathname)
url.pathname == location.pathname
updateCanonicalLink = ->
@canonicalLink ||= document.head.querySelector('link[rel="canonical"]')
@canonicalLink.setAttribute('href', "https://#{location.host}#{location.pathname}")

@ -96,15 +96,5 @@ module Docs
path = path.gsub %r{\+}, '_plus_'
path
end
def path_to_root
if subpath == ''
return '../'
else
previous_dirs = subpath.scan(/\//)
return '../' * previous_dirs.length
end
end
end
end

@ -6,8 +6,6 @@ module Docs
def call
if context[:external_urls]
root = path_to_root
css('a').each do |node|
next unless anchorUrl = node['href']
@ -24,7 +22,7 @@ module Docs
context[:external_urls].each do |host, name|
if url.host.to_s.match?(host)
node['href'] = root + name + url.path.to_s + '#' + url.fragment.to_s
node['href'] = '/' + name + url.path.to_s + '#' + url.fragment.to_s
end
end

Loading…
Cancel
Save