diff --git a/README.md b/README.md index c206839..04ba012 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ Preview the template here: https://digital-garden-jekyll-template.netlify.app/ - Based on Jekyll, a static website generator - Creates backlinks to other notes automatically +- Supports Roam-style double bracket link syntax to other notes - Features a simple and responsive design - Supports Markdown or HTML notes diff --git a/_notes/your-first-note.md b/_notes/your-first-note.md index 69e7a84..6f44142 100644 --- a/_notes/your-first-note.md +++ b/_notes/your-first-note.md @@ -7,9 +7,10 @@ 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). +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. You can display images using Markdown's image tag, like this: -![]({{page.image}}) \ No newline at end of file +![]({{page.image}}) diff --git a/_plugins/bidirectional_links_generator.rb b/_plugins/bidirectional_links_generator.rb index 25e9e7e..6203b10 100644 --- a/_plugins/bidirectional_links_generator.rb +++ b/_plugins/bidirectional_links_generator.rb @@ -1,11 +1,17 @@ # frozen_string_literal: true - class BidirectionalLinksGenerator < Jekyll::Generator def generate(site) - notes = site.collections['notes'].docs + all_notes = site.collections['notes'].docs - notes.each do |current_note| - notes_linking_to_current_note = notes.filter do |e| + all_notes.each do |current_note| + all_notes.each do |note_potentially_linked_to| + current_note.content = current_note.content.gsub( + /\[\[#{note_potentially_linked_to.data['title']}\]\]/i, + "#{note_potentially_linked_to.data['title']}" + ) + end + + notes_linking_to_current_note = all_notes.filter do |e| e.content.include?(current_note.url) end