Allow using note filename in double brackets

This commit is contained in:
Maxime Vaillancourt
2020-11-02 19:58:21 -05:00
parent 8538d12445
commit f297a68cbf
2 changed files with 9 additions and 1 deletions

View File

@@ -13,10 +13,18 @@ class BidirectionalLinksGenerator < Jekyll::Generator
# anchor tag elements (<a>) with "internal-link" CSS class
all_docs.each do |current_note|
all_docs.each do |note_potentially_linked_to|
# Replace double-bracketed links using note title
current_note.content = current_note.content.gsub(
/\[\[#{note_potentially_linked_to.data['title']}\]\]/i,
"<a class='internal-link' href='#{note_potentially_linked_to.url}'>#{note_potentially_linked_to.data['title']}</a>"
)
# Replace double-bracketed links using note filename
title_from_filename = File.basename(note_potentially_linked_to.basename, File.extname(note_potentially_linked_to.basename)).gsub('_', ' ').gsub('-', ' ').capitalize
current_note.content = current_note.content.gsub(
/\[\[#{title_from_filename}\]\]/i,
"<a class='internal-link' href='#{note_potentially_linked_to.url}'>#{title_from_filename}</a>"
)
end
# At this point, all remaining double-bracket-wrapped words are