Remove duplication in bidirectional links generator
This commit is contained in:
		
							parent
							
								
									264ba2bda1
								
							
						
					
					
						commit
						c1ba4ec61f
					
				| @ -20,32 +20,35 @@ class BidirectionalLinksGenerator < Jekyll::Generator | |||||||
|           File.extname(note_potentially_linked_to.basename) |           File.extname(note_potentially_linked_to.basename) | ||||||
|         ).gsub('_', ' ').gsub('-', ' ').capitalize |         ).gsub('_', ' ').gsub('-', ' ').capitalize | ||||||
| 
 | 
 | ||||||
|  |         new_href = "#{site.baseurl}#{note_potentially_linked_to.url}#{link_extension}" | ||||||
|  |         anchor_tag = "<a class='internal-link' href='#{new_href}'>\\1</a>" | ||||||
|  | 
 | ||||||
|         # Replace double-bracketed links with label using note title |         # Replace double-bracketed links with label using note title | ||||||
|         # [[A note about cats|this is a link to the note about cats]] |         # [[A note about cats|this is a link to the note about cats]] | ||||||
|         current_note.content = current_note.content.gsub( |         current_note.content = current_note.content.gsub( | ||||||
|           /\[\[#{title_from_filename}\|(.+?)(?=\])\]\]/i, |           /\[\[#{title_from_filename}\|(.+?)(?=\])\]\]/i, | ||||||
|           "<a class='internal-link' href='#{site.baseurl}#{note_potentially_linked_to.url}#{link_extension}'>\\1</a>" |           anchor_tag | ||||||
|         ) |         ) | ||||||
| 
 | 
 | ||||||
|         # Replace double-bracketed links with label using note filename |         # Replace double-bracketed links with label using note filename | ||||||
|         # [[cats|this is a link to the note about cats]] |         # [[cats|this is a link to the note about cats]] | ||||||
|         current_note.content = current_note.content.gsub( |         current_note.content = current_note.content.gsub( | ||||||
|           /\[\[#{note_potentially_linked_to.data['title']}\|(.+?)(?=\])\]\]/i, |           /\[\[#{note_potentially_linked_to.data['title']}\|(.+?)(?=\])\]\]/i, | ||||||
|           "<a class='internal-link' href='#{site.baseurl}#{note_potentially_linked_to.url}#{link_extension}'>\\1</a>" |           anchor_tag | ||||||
|         ) |         ) | ||||||
| 
 | 
 | ||||||
|         # Replace double-bracketed links using note title |         # Replace double-bracketed links using note title | ||||||
|         # [[a note about cats]] |         # [[a note about cats]] | ||||||
|         current_note.content = current_note.content.gsub( |         current_note.content = current_note.content.gsub( | ||||||
|           /\[\[(#{note_potentially_linked_to.data['title']})\]\]/i, |           /\[\[(#{note_potentially_linked_to.data['title']})\]\]/i, | ||||||
|           "<a class='internal-link' href='#{site.baseurl}#{note_potentially_linked_to.url}#{link_extension}'>\\1</a>" |           anchor_tag | ||||||
|         ) |         ) | ||||||
| 
 | 
 | ||||||
|         # Replace double-bracketed links using note filename |         # Replace double-bracketed links using note filename | ||||||
|         # [[cats]] |         # [[cats]] | ||||||
|         current_note.content = current_note.content.gsub( |         current_note.content = current_note.content.gsub( | ||||||
|           /\[\[(#{title_from_filename})\]\]/i, |           /\[\[(#{title_from_filename})\]\]/i, | ||||||
|           "<a class='internal-link' href='#{site.baseurl}#{note_potentially_linked_to.url}#{link_extension}'>\\1</a>" |           anchor_tag | ||||||
|         ) |         ) | ||||||
|       end |       end | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Maxime Vaillancourt
						Maxime Vaillancourt