@@ -9,10 +9,10 @@ class << self
9
9
10
10
def add_matching_files ( file_names , folder_path , pattern )
11
11
fullPattern = File . join ( folder_path , '*' ) #pattern
12
-
12
+
13
13
# NOTE: This is not a real reg-exp https://docs.ruby-lang.org/en/master/Dir.html#method-c-glob
14
14
# and actually, how it works is a mess
15
- # Trying to use a manual solution instead, filtering * with useable regex
15
+ # Trying to use a manual solution instead, filtering * with useable regex
16
16
Dir . glob ( fullPattern , File ::FNM_EXTGLOB ) . each do |file |
17
17
if file . match? ( pattern )
18
18
#puts "match: " + file
@@ -33,15 +33,15 @@ def save_from_markdownify(text)
33
33
text = text . gsub ( /\| / , "|" ) # |
34
34
end
35
35
36
- def is_external_url ?( url )
36
+ def is_prefixed_url ?( url )
37
37
if url =~ %r{^\w +://}
38
38
return true
39
39
end
40
40
return false
41
41
end
42
42
43
43
def prefixed_url ( url , base_url )
44
- if false == is_external_url ?( url )
44
+ if false == is_prefixed_url ?( url )
45
45
url = base_url + url
46
46
end
47
47
return url
@@ -58,12 +58,15 @@ def make_tooltip(page, page_links, id, url, needs_tooltip, match)
58
58
url = page_links [ id ] [ "url" ]
59
59
url = prefixed_url ( url , page . site . config [ "baseurl" ] )
60
60
end
61
-
62
- external_url = is_external_url? ( url )
61
+
62
+ # NOTE: Now we treat every link that has protocol prefix part as an external one
63
+ # that allows usage of direct links anywhere if needed (not recommended, plz use external_links.yml instead)
64
+ # but, at the same time requires e.g. all the really external links to be fully qualified (even in external_links.yml as well)
65
+ external_url = is_prefixed_url? ( url )
63
66
match = save_from_markdownify ( match )
64
67
replacement_text = '<a href="' + url + '" class="nav-link' + ( needs_tooltip ? ' content-tooltip' : '' ) + '"' + ( external_url ? ' target="_blank"' : '' ) + '>' + match + '</a>'
65
68
puts "replacement_text: " + replacement_text
66
-
69
+
67
70
return replacement_text
68
71
end
69
72
@@ -97,14 +100,14 @@ def process_markdown_parts(page, markdown)
97
100
# Split the content by special Markdown blocks
98
101
markdown_parts = markdown . split ( special_markdown_blocks_pattern )
99
102
#puts markdown_parts
100
- markdown_parts . each_with_index do |markdown_part , markdown_index |
103
+ markdown_parts . each_with_index do |markdown_part , markdown_index |
101
104
#puts "---------------\nmarkdown_index: " + markdown_index.to_s + "\n" + (markdown_index.even? ? "NONE " : "") + "markdown_part: " + markdown_part
102
105
103
106
page . data [ "page_links_ids_sorted_by_title" ] . each do |page_titles_data |
104
107
#puts "page_titles_data: #{page_titles_data}"
105
-
108
+
106
109
id = page_titles_data [ "id" ]
107
-
110
+
108
111
link_data = page_links [ id ]
109
112
# id = link_data["id"] these must match too
110
113
title = page_titles_data [ "title" ] # link_data["title"] is an array of titles that all must be already in the page_links_ids_sorted_by_title array
@@ -118,14 +121,14 @@ def process_markdown_parts(page, markdown)
118
121
pattern = pattern . gsub ( '\ ' , '[\s]+' )
119
122
#puts "searching for #{pattern}"
120
123
121
- if markdown_index . even?
124
+ if markdown_index . even?
122
125
# Content outside of special Markdown blocks, aka. pure text (NOTE: Also excludes the reqursively self added <a ...>title</a> tooltips/links)
123
126
124
127
# Search for known link titles
125
128
# NOTE: Using multi line matching here will not help either if the pattern itself is in the middle broken/spaned to multiple lines, so using whitespace replacements now inside the patter to handle this, see above!
126
129
full_pattern = /(^|[\s .,;:&'(])(#{ pattern } )([\s .,;:&')]|\z )(?![^<]*?<\/ a>)/
127
130
markdown_part = process_markdown_part ( page , markdown_part , page_links , full_pattern , id , url , needs_tooltip , true )
128
- else
131
+ else
129
132
# Content inside of special Markdown blocks
130
133
131
134
# Handle own auto tooltip links [[ ]], [[ | ]], [[ |id ]]
@@ -168,7 +171,7 @@ def write_to_file(file_path, content)
168
171
file . write ( content )
169
172
end
170
173
end
171
-
174
+
172
175
def process_nav_link_items ( items , ndx , nav_links_dictionary )
173
176
items . each do |item |
174
177
item [ 'nav_ndx' ] = ndx
@@ -182,14 +185,14 @@ def process_nav_link_items(items, ndx, nav_links_dictionary)
182
185
return ndx
183
186
end
184
187
185
- def is_excluded_title? ( excluded_titles , page_title )
188
+ def is_excluded_title? ( excluded_titles , page_title )
186
189
if excluded_titles and false == excluded_titles . empty?
187
190
# exluded list items can be a regex patters here
188
191
excluded_titles . each do |title |
189
192
title = title . gsub ( /\A '|'\z / , '' )
190
193
pattern = /^#{ title } $/
191
194
#pattern = Regexp.escape(title)
192
- if page_title . match? ( pattern )
195
+ if page_title . match? ( pattern )
193
196
return true
194
197
end
195
198
end
@@ -239,7 +242,7 @@ def gen_page_link_data(links_dir, link_files_pattern)
239
242
#page_links_dictionary = {}
240
243
link_file_names = [ ]
241
244
add_matching_files ( link_file_names , links_dir , link_files_pattern )
242
-
245
+
243
246
link_file_names . each do |file_name |
244
247
#puts file_name
245
248
yaml_content = YAML . load_file ( file_name )
@@ -271,7 +274,7 @@ def gen_page_link_data(links_dir, link_files_pattern)
271
274
}
272
275
273
276
# Add the page_link_data object to the ID dictionary
274
- # NOTE: Title duplications are allowed now [[title|id]] format must be used
277
+ # NOTE: Title duplications are allowed now [[title|id]] format must be used
275
278
# to get the propwer matching tooltip for duplicated title items
276
279
page_links_dictionary [ page_id ] = page_link_data
277
280
end
@@ -341,8 +344,8 @@ def JekyllTooltipGen_debug_page_info(page, details = true)
341
344
def JekyllTooltipGen_debug_filter_pages? ( page )
342
345
debug_pages = {
343
346
# "doc/README.md" => true,
344
- }
345
- debug_ok = true
347
+ }
348
+ debug_ok = true
346
349
# Comment this line out if not debugging!!!
347
350
# debug_ok = (debug_pages[page.relative_path] != nil && debug_pages[page.relative_path])
348
351
return debug_ok
@@ -362,15 +365,15 @@ def JekyllTooltipGen_hack_description_in(page_has_subtitle, page_has_description
362
365
if page_has_description || page_has_subtitle
363
366
# NOTE: Additional line breaks are essential here otherwise special constructs like tables, liquid notice or code block, etc. might break
364
367
# Added double \n\n just to be prepared for the case if there's no \n at all at the file ending
365
- page . content = page . content + "\n \n " + desc_hack_separator + description
368
+ page . content = page . content + "\n \n " + desc_hack_separator + description
366
369
end
367
370
end
368
371
369
372
def JekyllTooltipGen_hack_description_out ( page_has_subtitle , page_has_description , page , desc_hack_separator )
370
373
description = nil
371
374
372
375
content_parts = page . content . split ( desc_hack_separator )
373
- content_parts . each_with_index do |content_part , content_part_index |
376
+ content_parts . each_with_index do |content_part , content_part_index |
374
377
#puts "---------------\ncontent_part_index: " + content_part_index.to_s + "\ncontent_part: " + content_part
375
378
if content_part_index . even?
376
379
page . content = content_part
@@ -412,7 +415,7 @@ def JekyllTooltipGen_hack_description_out(page_has_subtitle, page_has_descriptio
412
415
413
416
# 1st pass
414
417
#
415
- # This is used now to
418
+ # This is used now to
416
419
# - set the page nav_ndx correctly to support our custom bottom collection elements navigator
417
420
# - set additional page data elements that will be used during all the passes
418
421
#
@@ -424,7 +427,7 @@ def JekyllTooltipGen_hack_description_out(page_has_subtitle, page_has_descriptio
424
427
$JekyllTooltipGen_should_build_tooltips = ( ENV [ 'JEKYLL_BUILD_TOOLTIPS' ] == 'yes' )
425
428
$JekyllTooltipGen_should_build_persistent_tooltips = ( ENV [ 'JEKYLL_BUILD_PERSISTENT_TOOLTIPS' ] == 'yes' )
426
429
end
427
- next if false == $JekyllTooltipGen_should_build_tooltips
430
+ next if false == $JekyllTooltipGen_should_build_tooltips
428
431
429
432
if $JekyllTooltipGen_markdown_extensions == nil
430
433
$JekyllTooltipGen_markdown_extensions = site . config [ 'markdown_ext' ] . split ( ',' ) . map { |ext | ".#{ ext . strip } " }
@@ -443,25 +446,25 @@ def JekyllTooltipGen_hack_description_out(page_has_subtitle, page_has_descriptio
443
446
444
447
next if false == $JekyllTooltipGen_markdown_extensions. include? ( File . extname ( page . relative_path ) ) && File . extname ( page . relative_path ) != ".html"
445
448
446
- page_url = page . url . gsub ( /\. [^.]+$/ , '' )
449
+ page_url = page . url . gsub ( /\. [^.]+$/ , '' )
447
450
if ( link_data = $JekyllTooltipGen_nav_links[ page_url ] ) != nil
448
451
page . data [ 'nav_ndx' ] = link_data [ 'nav_ndx' ] # page_pagination.html will use this as sort value for navigation ordering
449
452
end
450
453
page . data [ "page_links" ] = $JekyllTooltipGen_page_links
451
454
page . data [ "page_links_ids_sorted_by_title" ] = $JekyllTooltipGen_page_links_ids_sorted_by_title
452
- # puts "collection: " + (page.respond_to?(:collection) ? page.collection.label : "") + ", nav_ndx: " + (link_data != nil ? link_data['nav_ndx'].to_s : "") + ", page_url: #{page_url}, page: #{page.relative_path}"
455
+ # puts "collection: " + (page.respond_to?(:collection) ? page.collection.label : "") + ", nav_ndx: " + (link_data != nil ? link_data['nav_ndx'].to_s : "") + ", page_url: #{page_url}, page: #{page.relative_path}"
453
456
end
454
457
end
455
458
end
456
459
457
460
# 2nd pass
458
461
#
459
- # This is used now to
462
+ # This is used now to
460
463
# - add the description to the page end to get it rendred correclty the same way, together with the page content (will be removed/handled in the 3rd pass)
461
464
# - render the page content manually and create the autolinks and tooltips
462
465
#
463
466
Jekyll ::Hooks . register [ :pages , :documents ] , :pre_render do |page , payload |
464
- next if false == $JekyllTooltipGen_should_build_tooltips
467
+ next if false == $JekyllTooltipGen_should_build_tooltips
465
468
next if false == $JekyllTooltipGen_markdown_extensions. include? ( File . extname ( page . relative_path ) ) && File . extname ( page . relative_path ) != ".html"
466
469
next if false == JekyllTooltipGen_debug_filter_pages? ( page )
467
470
@@ -487,14 +490,14 @@ def JekyllTooltipGen_hack_description_out(page_has_subtitle, page_has_descriptio
487
490
488
491
# 3rd pass
489
492
#
490
- # This is used now to
493
+ # This is used now to
491
494
# - remove the added hackish description block from the page end and replace the description with the now correctly rendered one
492
495
#
493
496
Jekyll ::Hooks . register [ :pages , :documents ] , :post_convert do |page |
494
497
next if false == $JekyllTooltipGen_should_build_tooltips
495
498
next if false == $JekyllTooltipGen_markdown_extensions. include? ( File . extname ( page . relative_path ) ) && File . extname ( page . relative_path ) != ".html"
496
499
next if false == JekyllTooltipGen_debug_filter_pages? ( page )
497
-
500
+
498
501
page_has_subtitle = ( page . data [ "subtitle" ] && false == page . data [ "subtitle" ] . empty? )
499
502
page_has_description = ( page . data [ "description" ] && false == page . data [ "description" ] . empty? )
500
503
JekyllTooltipGen_hack_description_out ( page_has_subtitle , page_has_description , page , JekyllTooltipGen_desc_hack_separator )
0 commit comments