Add support for Roam-style double bracket link syntax
This commit is contained in:
		
							parent
							
								
									84110177d8
								
							
						
					
					
						commit
						a0b0b12e41
					
				| @ -10,6 +10,7 @@ Preview the template here: https://digital-garden-jekyll-template.netlify.app/ | |||||||
| 
 | 
 | ||||||
| - Based on Jekyll, a static website generator | - Based on Jekyll, a static website generator | ||||||
| - Creates backlinks to other notes automatically | - Creates backlinks to other notes automatically | ||||||
|  | - Supports Roam-style double bracket link syntax to other notes | ||||||
| - Features a simple and responsive design | - Features a simple and responsive design | ||||||
| - Supports Markdown or HTML notes | - Supports Markdown or HTML notes | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -7,6 +7,7 @@ This is your first note. | |||||||
| 
 | 
 | ||||||
| To link to another note, use regular Markdown syntax for links, with a relative link to the other note, like this: [this is a link to a note about cats](/cats). | To link to another note, use regular Markdown syntax for links, with a relative link to the other note, like this: [this is a link to a note about cats](/cats). | ||||||
| 
 | 
 | ||||||
|  | You can also use Roam-style link syntax by wrapping a note's title in double brackets, like this: [[A note about cats]]. If the Roam-style link does not point to a valid note's title, the double brackets will still be shown, like this: [[This note does not exist]]. | ||||||
| 
 | 
 | ||||||
| Notice in the "Notes mentioning this note" section that there is another note linking to this note. This is a bi-directional link, and those are automatically created when you create links to other notes. | Notice in the "Notes mentioning this note" section that there is another note linking to this note. This is a bi-directional link, and those are automatically created when you create links to other notes. | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -1,11 +1,17 @@ | |||||||
| # frozen_string_literal: true | # frozen_string_literal: true | ||||||
| 
 |  | ||||||
| class BidirectionalLinksGenerator < Jekyll::Generator | class BidirectionalLinksGenerator < Jekyll::Generator | ||||||
|   def generate(site) |   def generate(site) | ||||||
|     notes = site.collections['notes'].docs |     all_notes = site.collections['notes'].docs | ||||||
| 
 | 
 | ||||||
|     notes.each do |current_note| |     all_notes.each do |current_note| | ||||||
|       notes_linking_to_current_note = notes.filter do |e| |       all_notes.each do |note_potentially_linked_to| | ||||||
|  |         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>" | ||||||
|  |         ) | ||||||
|  |       end | ||||||
|  | 
 | ||||||
|  |       notes_linking_to_current_note = all_notes.filter do |e| | ||||||
|         e.content.include?(current_note.url) |         e.content.include?(current_note.url) | ||||||
|       end |       end | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Maxime Vaillancourt
						Maxime Vaillancourt