Add support for optional label in double-bracket links
This commit is contained in:
@@ -13,14 +13,34 @@ 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|
|
||||
title_from_filename = File.basename(
|
||||
note_potentially_linked_to.basename,
|
||||
File.extname(note_potentially_linked_to.basename)
|
||||
).gsub('_', ' ').gsub('-', ' ').capitalize
|
||||
|
||||
# Replace double-bracketed links with label using note title
|
||||
# [[A note about cats|this is a link to the note about cats]]
|
||||
current_note.content = current_note.content.gsub(
|
||||
/\[\[#{title_from_filename}\|(.+?)(?=\])\]\]/i,
|
||||
"<a class='internal-link' href='#{note_potentially_linked_to.url}'>\\1</a>"
|
||||
)
|
||||
|
||||
# Replace double-bracketed links with label using note filename
|
||||
# [[cats|this is a link to the note about cats]]
|
||||
current_note.content = current_note.content.gsub(
|
||||
/\[\[#{note_potentially_linked_to.data['title']}\|(.+?)(?=\])\]\]/i,
|
||||
"<a class='internal-link' href='#{note_potentially_linked_to.url}'>\\1</a>"
|
||||
)
|
||||
|
||||
# Replace double-bracketed links using note title
|
||||
# [[a note about cats]]
|
||||
current_note.content = current_note.content.gsub(
|
||||
/\[\[(#{note_potentially_linked_to.data['title']})\]\]/i,
|
||||
"<a class='internal-link' href='#{note_potentially_linked_to.url}'>\\1</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
|
||||
# [[cats]]
|
||||
current_note.content = current_note.content.gsub(
|
||||
/\[\[(#{title_from_filename})\]\]/i,
|
||||
"<a class='internal-link' href='#{note_potentially_linked_to.url}'>\\1</a>"
|
||||
|
||||
Reference in New Issue
Block a user