Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add external_urls filter #1495

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion assets/javascripts/lib/page.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For https://devdocs.io/typescript/declaration-files/do-s-and-don-ts#function-overloads, location.pathname is "/typescript/declaration-files/do-s-and-don-ts".

Remove the console.log statements?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

console.log removed and now should work checking only the initial path of the pathname.


updateCanonicalLink = ->
@canonicalLink ||= document.head.querySelector('link[rel="canonical"]')
@canonicalLink.setAttribute('href', "https://#{location.host}#{location.pathname}")
Expand Down
10 changes: 0 additions & 10 deletions lib/docs/core/filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,5 @@ def clean_path(path)
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
4 changes: 1 addition & 3 deletions lib/docs/filters/core/external_urls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ class ExternalUrlsFilter < Filter
def call
if context[:external_urls]

root = path_to_root

css('a').each do |node|

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

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

Expand Down