Allow using note filename in double brackets

This commit is contained in:
Maxime Vaillancourt 2020-11-02 19:58:21 -05:00
parent 8538d12445
commit f297a68cbf
2 changed files with 9 additions and 1 deletions

View File

@ -8,7 +8,7 @@ permalink: /
# Welcome! 🌱
<p style="padding: 3em 1em; background: #f5f7ff; border-radius: 4px;">
Take a look at <span style="font-weight: bold">[[Your first seed]]</span> to get started on your exploration.
Take a look at <span style="font-weight: bold">[[Your first note]]</span> to get started on your exploration.
</p>
This digital garden template is free, open-source, and [available on GitHub here](https://github.com/maximevaillancourt/digital-garden-jekyll-template).

View File

@ -13,10 +13,18 @@ class BidirectionalLinksGenerator < Jekyll::Generator
# anchor tag elements (<a>) 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,
"<a class='internal-link' href='#{note_potentially_linked_to.url}'>#{note_potentially_linked_to.data['title']}</a>"
)
# 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,
"<a class='internal-link' href='#{note_potentially_linked_to.url}'>#{title_from_filename}</a>"
)
end
# At this point, all remaining double-bracket-wrapped words are