Skip to content

Commit cc3b215

Browse files
committed
Title exclusion logic fixes
- title exclusion is now handled in the sorted id list - [[|ID]] custom markdown links and aliases now overrides correctly the exclusion title list - also, Fixed an uppercase link again Signed-off-by: Hofi <hofione@gmail.com>
1 parent 181ae7d commit cc3b215

File tree

2 files changed

+54
-34
lines changed

2 files changed

+54
-34
lines changed

_plugins/generate_tooltips.rb

Lines changed: 53 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,23 @@ def make_tooltip(page, page_links, id, url, match)
5555
#puts "match_parts: #{match_parts}"
5656
match = match_parts[0]
5757
id = match_parts[1]
58-
url = page_links[id]["url"]
58+
link_data = page_links[id]
59+
if link_data != nil
60+
url = link_data["url"]
5961
url = prefixed_url(url, page.site.config["baseurl"])
62+
else
63+
puts "Error: Unknown ID in matching part: #{match_parts}"
64+
return match
65+
end
66+
end
67+
68+
if id == nil or id.length <= 0
69+
puts "Error: Empty ID in matching part: #{match}"
70+
return match
71+
end
72+
if url == nil or url.length <= 0
73+
puts "Error: Empty URL for ID: #{id} in matching part: #{match}"
74+
return match
6075
end
6176

6277
# NOTE: Now we treat every link that has protocol prefix part as an external one
@@ -65,7 +80,7 @@ def make_tooltip(page, page_links, id, url, match)
6580
external_url = is_prefixed_url?(url)
6681
match = save_from_markdownify(match)
6782
replacement_text = '<a href="' + url + '" class="nav-link content-tooltip"' + (external_url ? ' target="_blank"' : '') + '>' + match + '</a>'
68-
puts "replacement_text: " + replacement_text
83+
# puts "replacement_text: " + replacement_text
6984

7085
return replacement_text
7186
end
@@ -101,41 +116,47 @@ def process_markdown_parts(page, markdown)
101116
markdown_parts = markdown.split(special_markdown_blocks_pattern)
102117
#puts markdown_parts
103118
markdown_parts.each_with_index do |markdown_part, markdown_index|
104-
#puts "---------------\nmarkdown_index: " + markdown_index.to_s + "\n" + (markdown_index.even? ? "NONE " : "") + "markdown_part: " + markdown_part
119+
# puts "---------------\nmarkdown_index: " + markdown_index.to_s + "\n" + (markdown_index.even? ? "NOT " : "") + "markdown_part: " + markdown_part
105120

106-
page.data["page_links_ids_sorted_by_title"].each do |page_titles_data|
121+
page.data["filtered_page_ids_sorted_by_title_len"].each do |page_titles_data|
107122
#puts "page_titles_data: #{page_titles_data}"
108123

109124
id = page_titles_data["id"]
110125

111-
link_data = page_links[id]
112-
# id = link_data["id"] these must match too
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
126+
link_data = page_links[id] # id and link_data["id"] must match always at this point
127+
title = page_titles_data["title"] # link_data["title"] is an array of titles that all must be represented by ID already in the filtered_page_ids_sorted_by_title_len array
114128
url = prefixed_url(link_data["url"], base_url)
115129

116-
#puts "searching for #{title}"
117130
pattern = Regexp.escape(title)
118-
#puts "searching for #{pattern}"
119-
# TODO: Even though this one helps finding the pattern e.g. if it spans to multiple line or separated inside with different whitespaces, but can cause unwanted sideffects and has generation time penalities, revise later!
131+
# TODO: Even though this one helps finding the pattern e.g. if it spans to multiple line or separated inside with different whitespaces, but
132+
# also can cause unwanted sideffects and has generation time penalities, revise later!
120133
pattern = pattern.gsub('\ ', '[\s]+')
121-
#puts "searching for #{pattern}"
134+
#puts "searching for #{title} with pattern #{pattern}"
122135

123136
if markdown_index.even?
124137
# Content outside of special Markdown blocks, aka. pure text (NOTE: Also excludes the reqursively self added <a ...>title</a> tooltips/links)
125138

126139
# Search for known link titles
127-
# 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!
140+
# NOTE: Using multi line matching here will not help either if the pattern itself is in the middle broken/spaned to multiple lines, so
141+
# using whitespace replacements now inside the patter to handle this, see above!
128142
full_pattern = /(^|[\s.,;:&'"(])(#{pattern})([\s.,;:&'")]|\z)(?![^<]*?<\/a>)/
129143
markdown_part = process_markdown_part(page, markdown_part, page_links, full_pattern, id, url, true)
130144
else
131145
# Content inside of special Markdown blocks
132146

133-
# Handle own auto tooltip links [[ ]], [[ | ]], [[ |id ]]
134-
full_pattern = /(\[\[)(#{pattern}|#{pattern}\|.+|.*\|#{id})(\]\])/
147+
# Handle own auto\tooltip links [[title]], but NOT [[title|id]], see bellow why
148+
full_pattern = /(\[\[)(#{pattern})(\]\])/
135149
markdown_part = process_markdown_part(page, markdown_part, page_links, full_pattern, id, url, false)
136150
end
137151
end
138152

153+
if markdown_index.odd?
154+
# Handle own auto\tooltip links [[title|id]]
155+
# This must be a separate run, as independent from the given title, if ID is presented it will always override title, and title exclusion as well
156+
full_pattern = /(\[\[)(.+\|.+)(\]\])/
157+
markdown_part = process_markdown_part(page, markdown_part, page_links, full_pattern, nil, nil, false)
158+
end
159+
139160
#puts "new markdown_part: " + markdown_part
140161
markdown_parts[markdown_index] = markdown_part
141162
end
@@ -216,14 +237,18 @@ def gen_nav_link_data(nav_links_file)
216237
return nav_links_dictionary
217238
end # gen_nav_link_data
218239

219-
def page_links_ids_sorted_by_title(page_links)
240+
def filtered_page_ids_sorted_by_title_len(page_links)
241+
excluded_titles = YAML.load_file(JekyllTooltipGen_excluded_yaml)
220242
sorted_arr = []
221243

222244
page_links.each do |page_id, page_data|
223245
#puts "page_id: #{page_id}, page_data: #{page_data}"
224246
titles = page_data["title"]
225247

226248
titles.each do |title|
249+
# Skip excluded titles
250+
next if is_excluded_title?(excluded_titles, title)
251+
227252
sorted_arr << page_link_data = {
228253
"id" => page_id,
229254
"title" => title,
@@ -236,11 +261,15 @@ def page_links_ids_sorted_by_title(page_links)
236261
# 'Soft macros' before 'macros'
237262
# In most of the cases matching the longer titles first will eliminate such issues
238263
sorted_arr.sort_by { |page| page["title"].length }.reverse
264+
265+
# Just for debugging
266+
# sorted_arr.each do |data|
267+
# puts data
268+
# end
239269
end
240270

241271
def gen_page_link_data(links_dir, link_files_pattern)
242272
link_aliases = YAML.load_file(JekyllTooltipGen_link_aliases_yaml)
243-
excluded_titles = YAML.load_file(JekyllTooltipGen_excluded_yaml)
244273
page_links_dictionary = YAML.load_file(JekyllTooltipGen_external_yaml)
245274
#page_links_dictionary = {}
246275
link_file_names = []
@@ -258,13 +287,10 @@ def gen_page_link_data(links_dir, link_files_pattern)
258287
page_title = page_title.gsub(/\A[#{Regexp.escape(chars_to_remove)}]+|[#{Regexp.escape(chars_to_remove)}]+\z/, '')
259288
#puts "page_title: " + page_title
260289
if page_title.length == 0
261-
puts "Page title is empty, ID: #{page_id}"
290+
puts "Error: Page title is empty, ID: #{page_id}"
262291
exit 3
263292
end
264293

265-
# Skip excluded titles
266-
next if is_excluded_title?(excluded_titles, page_title)
267-
268294
# Create a new page_link_data object
269295
page_link_data = {
270296
"id" => page_id,
@@ -283,25 +309,18 @@ def gen_page_link_data(links_dir, link_files_pattern)
283309

284310
page_link_data = page_links_dictionary[alias_id]
285311
if page_link_data == nil
286-
puts "Unknow ID (#{alias_id}) in alias definition"
312+
puts "Error: Unknow ID (#{alias_id}) in alias definition"
287313
exit 4
288314
end
289315
page_link_data["title"].concat(alias_data["aliases"])
290316
# puts "page_link_data: #{page_link_data}"
291317
end
292318

293-
# Just for debugging
294-
# pp page_links_dictionary
295-
# page_links_ids_sorted_by_title(page_links_dictionary).each do |data|
296-
# puts data
297-
# end
298-
299319
#pp page_links_dictionary
300320
return page_links_dictionary
301321
end # gen_page_link_data
302322

303323
def generate_tooltips(page, write_back)
304-
puts "------------------------------------"
305324
puts "collection: " + (page.respond_to?(:collection) ? page.collection.label : "") + ", ndx: #{page.data["nav_ndx"]}, relative_path: #{page.relative_path}"
306325
puts "------------------------------------"
307326

@@ -383,7 +402,7 @@ def JekyllTooltipGen_hack_description_in(page_has_subtitle, page_has_description
383402

384403
$JekyllTooltipGen_markdown_extensions = nil
385404
$JekyllTooltipGen_page_links = nil
386-
$JekyllTooltipGen_page_links_ids_sorted_by_title = nil
405+
$JekyllTooltipGen_filtered_page_ids_sorted_by_title_len = nil
387406
$JekyllTooltipGen_nav_links = nil
388407
$JekyllTooltipGen_should_build_tooltips = nil
389408
$JekyllTooltipGen_should_build_persistent_tooltips = nil
@@ -399,6 +418,7 @@ def JekyllTooltipGen_hack_description_in(page_has_subtitle, page_has_description
399418
# as that needs proper per-page payload data (or TODO: figure out how to get it in that case properly)
400419
#
401420
Jekyll::Hooks.register :site, :pre_render do |site|
421+
puts "------------------------------------"
402422
if $JekyllTooltipGen_should_build_tooltips == nil
403423
$JekyllTooltipGen_should_build_tooltips = (ENV['JEKYLL_BUILD_TOOLTIPS'] == 'yes')
404424
$JekyllTooltipGen_should_build_persistent_tooltips = (ENV['JEKYLL_BUILD_PERSISTENT_TOOLTIPS'] == 'yes')
@@ -408,17 +428,17 @@ def JekyllTooltipGen_hack_description_in(page_has_subtitle, page_has_description
408428
if $JekyllTooltipGen_markdown_extensions == nil
409429
$JekyllTooltipGen_markdown_extensions = site.config['markdown_ext'].split(',').map { |ext| ".#{ext.strip}" }
410430
# Skip shorter than 3 letter long (e.g. Glossary header) anchor items (for testing: https://rubular.com/)
411-
$JekyllTooltipGen_page_links = Jekyll::TooltipGen.gen_page_link_data(JekyllTooltipGen_links_folder, /\/(adm|dev|doc|site)-(([^#]+)|(.*\#{1}.{3,}))\.yml\z/) # /\/(adm|dev|doc)-(([^#]+)|(.*\#{1}.{3,}))\.yml\z/ 'adm-temp-macro-ose#message.yml'
431+
$JekyllTooltipGen_page_links = Jekyll::TooltipGen.gen_page_link_data(JekyllTooltipGen_links_folder, /\/(adm|dev|doc|site)-(([^#]+)|(.*\#{1}.{3,}))\.yml\z/)
412432
# Sort the $JekyllTooltipGen_page_links dictionary keys based on the "title" values in reverse order case insensitive
413-
$JekyllTooltipGen_page_links_ids_sorted_by_title = Jekyll::TooltipGen.page_links_ids_sorted_by_title($JekyllTooltipGen_page_links)
433+
$JekyllTooltipGen_filtered_page_ids_sorted_by_title_len = Jekyll::TooltipGen.filtered_page_ids_sorted_by_title_len($JekyllTooltipGen_page_links)
414434
# Create $JekyllTooltipGen_nav_links dictionary using "url" as key and add nav_ndx to all items based on we can adjust navigation order (in page_pagination.html)
415435
# TODO: We can replace the nav_gen shell tool now to handle everything related to link generation at a single place
416436
$JekyllTooltipGen_nav_links = Jekyll::TooltipGen.gen_nav_link_data(JekyllTooltipGen_navigation_yaml)
417437
end
418438

419439
[site.pages, site.documents].each do |pages|
420440
pages.each do |page|
421-
#JekyllTooltipGen_debug_page_info(page, true)
441+
# JekyllTooltipGen_debug_page_info(page, false)
422442

423443
next if false == $JekyllTooltipGen_markdown_extensions.include?(File.extname(page.relative_path)) && File.extname(page.relative_path) != ".html"
424444

@@ -427,7 +447,7 @@ def JekyllTooltipGen_hack_description_in(page_has_subtitle, page_has_description
427447
page.data['nav_ndx'] = link_data['nav_ndx'] # page_pagination.html will use this as sort value for navigation ordering
428448
end
429449
page.data["page_links"] = $JekyllTooltipGen_page_links
430-
page.data["page_links_ids_sorted_by_title"] = $JekyllTooltipGen_page_links_ids_sorted_by_title
450+
page.data["filtered_page_ids_sorted_by_title_len"] = $JekyllTooltipGen_filtered_page_ids_sorted_by_title_len
431451
# 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}"
432452

433453
page_has_subtitle = (page.data["subtitle"] && false == page.data["subtitle"].empty?)

doc/_dev-guide/chapter_4/section_2/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Like every project syslog-ng also uses different libraries and build-systems tha
5959
* criterion
6060
* gcc@11
6161

62-
**Hint:** If you you have [[syslog-ng installed via brew|dev-inst-macos#Installation]], as a reference, you can check the dependencies of the brew built version using `brew deps syslog-ng`
62+
**Hint:** If you you have [[syslog-ng installed via brew|dev-inst-macos#installation]], as a reference, you can check the dependencies of the brew built version using `brew deps syslog-ng`
6363
{: .notice--info}
6464

6565
This is how it might look like if you start from the ground:

0 commit comments

Comments
 (0)