-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This filter traverses all <a> tags and replaces its url for an url poiting to a path of an existant documentation.
- Loading branch information
1 parent
e9d7849
commit 38e2b10
Showing
6 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
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 | ||
end | ||
end | ||
|
||
end | ||
end | ||
|
||
doc | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters