Add support for Roam-style double bracket link syntax

This commit is contained in:
Maxime Vaillancourt 2020-05-30 13:12:51 -04:00
parent 84110177d8
commit a0b0b12e41
3 changed files with 13 additions and 5 deletions

View File

@ -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

View File

@ -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}})
![]({{page.image}})

View File

@ -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,
"<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)
end