From f297a68cbf517ba145e35f447f90799212610f14 Mon Sep 17 00:00:00 2001 From: Maxime Vaillancourt Date: Mon, 2 Nov 2020 19:58:21 -0500 Subject: [PATCH] Allow using note filename in double brackets --- _pages/index.md | 2 +- _plugins/bidirectional_links_generator.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/_pages/index.md b/_pages/index.md index 815bee4..7d35ce3 100644 --- a/_pages/index.md +++ b/_pages/index.md @@ -8,7 +8,7 @@ permalink: / # Welcome! 🌱

- Take a look at [[Your first seed]] to get started on your exploration. + Take a look at [[Your first note]] to get started on your exploration.

This digital garden template is free, open-source, and [available on GitHub here](https://github.com/maximevaillancourt/digital-garden-jekyll-template). diff --git a/_plugins/bidirectional_links_generator.rb b/_plugins/bidirectional_links_generator.rb index 70f956f..3c7733c 100644 --- a/_plugins/bidirectional_links_generator.rb +++ b/_plugins/bidirectional_links_generator.rb @@ -13,10 +13,18 @@ class BidirectionalLinksGenerator < Jekyll::Generator # anchor tag elements () with "internal-link" CSS class all_docs.each do |current_note| all_docs.each do |note_potentially_linked_to| + # Replace double-bracketed links using note title current_note.content = current_note.content.gsub( /\[\[#{note_potentially_linked_to.data['title']}\]\]/i, "#{note_potentially_linked_to.data['title']}" ) + + # Replace double-bracketed links using note filename + title_from_filename = File.basename(note_potentially_linked_to.basename, File.extname(note_potentially_linked_to.basename)).gsub('_', ' ').gsub('-', ' ').capitalize + current_note.content = current_note.content.gsub( + /\[\[#{title_from_filename}\]\]/i, + "#{title_from_filename}" + ) end # At this point, all remaining double-bracket-wrapped words are