From c1ba4ec61fc103907627d7228cd3861db7593790 Mon Sep 17 00:00:00 2001 From: Maxime Vaillancourt Date: Sun, 14 Mar 2021 20:37:47 -0400 Subject: [PATCH] Remove duplication in bidirectional links generator --- _plugins/bidirectional_links_generator.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/_plugins/bidirectional_links_generator.rb b/_plugins/bidirectional_links_generator.rb index 90fe62a..1d89e00 100644 --- a/_plugins/bidirectional_links_generator.rb +++ b/_plugins/bidirectional_links_generator.rb @@ -20,32 +20,35 @@ class BidirectionalLinksGenerator < Jekyll::Generator File.extname(note_potentially_linked_to.basename) ).gsub('_', ' ').gsub('-', ' ').capitalize + new_href = "#{site.baseurl}#{note_potentially_linked_to.url}#{link_extension}" + anchor_tag = "\\1" + # 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, - "\\1" + anchor_tag ) # 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, - "\\1" + anchor_tag ) # 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, - "\\1" + anchor_tag ) # Replace double-bracketed links using note filename # [[cats]] current_note.content = current_note.content.gsub( /\[\[(#{title_from_filename})\]\]/i, - "\\1" + anchor_tag ) end