Skip to content

Commit 65b303f

Browse files
committed
generate_tooltips: add support of open in blank page option in the links
Signed-off-by: Hofi <hofione@gmail.com>
1 parent 1730419 commit 65b303f

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

_plugins/generate_tooltips.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def is_modifiable_markdown_part?(part)
5454
end
5555

5656
def make_tooltip(page, page_links, id, url, match)
57+
use_blank = false
5758
match_parts = match.split(/(?<!\\)\|/)
5859

5960
# If the text has an '|' it means it comes from our special autolink/tooltip [[text|id]] markdown block
@@ -74,6 +75,7 @@ def make_tooltip(page, page_links, id, url, match)
7475
end
7576
link_data = page_links[id]
7677
if link_data != nil
78+
use_blank = link_data["open_in_blank"]
7779
url = link_data["url"]
7880
url = prefixed_url(url, page.site.config["baseurl"])
7981
else
@@ -99,7 +101,7 @@ def make_tooltip(page, page_links, id, url, match)
99101
# NOTE: Now we treat every link that has protocol prefix part as an external one
100102
# that allows usage of direct links anywhere if needed (not recommended, plz use external_links.yml instead)
101103
# but, at the same time requires e.g. all the really external links to be fully qualified (even in external_links.yml as well)
102-
external_url = is_prefixed_url?(url)
104+
external_url = is_prefixed_url?(url) || use_blank
103105
title = save_from_markdownify(title)
104106
replacement_text = '<a href="' + url + '" class="nav-link content-tooltip"' + (external_url ? ' target="_blank"' : '') + '>' + title + '</a>'
105107
# puts "replacement_text: " + replacement_text
@@ -345,6 +347,7 @@ def gen_page_link_data(links_dir, link_files_pattern)
345347
page_id = yaml_content['id']
346348
page_url = yaml_content['url']
347349
page_title = yaml_content['title']
350+
open_in_blank = yaml_content['open_in_blank']
348351
chars_to_remove = %{"'}
349352
page_title = page_title.gsub(/\A[#{Regexp.escape(chars_to_remove)}]+|[#{Regexp.escape(chars_to_remove)}]+\z/, '')
350353
#puts "page_title: " + page_title
@@ -358,6 +361,7 @@ def gen_page_link_data(links_dir, link_files_pattern)
358361
"id" => page_id,
359362
"url" => page_url,
360363
"title" => [ page_title ],
364+
"open_in_blank" => open_in_blank,
361365
}
362366

363367
# Add the page_link_data object to the ID dictionary
@@ -423,7 +427,7 @@ def JekyllTooltipGen_debug_page_info(page, details = true)
423427
def JekyllTooltipGen_debug_filter_pages?(page)
424428
debug_pages = {
425429
# "doc/README.md" => true,
426-
}
430+
}
427431
debug_ok = true
428432
# Comment this line out if not debugging!!!
429433
# debug_ok = (debug_pages[page.relative_path] != nil && debug_pages[page.relative_path])

0 commit comments

Comments
 (0)