-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
base: main
Are you sure you want to change the base?
Add external_urls filter #1495
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,38 @@ | ||||||
# frozen_string_literal: true | ||||||
|
||||||
module Docs | ||||||
class ExternalUrlsFilter < Filter | ||||||
|
||||||
def call | ||||||
if context[:external_urls] | ||||||
|
||||||
root = path_to_root | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we simply use the following?
Suggested change
|
||||||
|
||||||
css('a').each do |node| | ||||||
|
||||||
next unless anchorUrl = node['href'] | ||||||
|
||||||
# avoid links already converted to internal links | ||||||
next if anchorUrl.match?(/\.\./) | ||||||
|
||||||
if context[:external_urls].is_a?(Proc) | ||||||
node['href'] = context[:external_urls].call(anchorUrl) | ||||||
next | ||||||
end | ||||||
|
||||||
url = URI(anchorUrl) | ||||||
|
||||||
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 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The generated link is correct, but does not work in devdocs. Presumably a JavaScript call to Screen.Recording.2021-03-13.at.19.44.22.mov |
||||||
end | ||||||
end | ||||||
|
||||||
end | ||||||
end | ||||||
|
||||||
doc | ||||||
end | ||||||
|
||||||
end | ||||||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/existant/existing