Update generator to include baseurl.

One of the breaking errors that I fixed in my install of this great repo was that all links generated by the ruby script didn't take into account the baseurl specified in the config file.

This ruby file corrects the error, although in the paths it might add one '/' too many. This hasn't caused me any issues, but should be considered.
This commit is contained in:
Alan M 2021-01-31 01:38:24 -06:00 committed by GitHub
parent 9232ce3ded
commit d22fcbef35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -24,28 +24,28 @@ class BidirectionalLinksGenerator < Jekyll::Generator
# [[A note about cats|this is a link to the note about cats]]
current_note.content = current_note.content.gsub(
/\[\[#{title_from_filename}\|(.+?)(?=\])\]\]/i,
"<a class='internal-link' href='#{note_potentially_linked_to.url}#{link_extension}'>\\1</a>"
"<a class='internal-link' href='#{site.baseurl}#{note_potentially_linked_to.url}#{link_extension}'>\\1</a>"
)
# Replace double-bracketed links with label using note filename
# [[cats|this is a link to the note about cats]]
current_note.content = current_note.content.gsub(
/\[\[#{note_potentially_linked_to.data['title']}\|(.+?)(?=\])\]\]/i,
"<a class='internal-link' href='#{note_potentially_linked_to.url}#{link_extension}'>\\1</a>"
"<a class='internal-link' href='#{site.baseurl}#{note_potentially_linked_to.url}#{link_extension}'>\\1</a>"
)
# Replace double-bracketed links using note title
# [[a note about cats]]
current_note.content = current_note.content.gsub(
/\[\[(#{note_potentially_linked_to.data['title']})\]\]/i,
"<a class='internal-link' href='#{note_potentially_linked_to.url}#{link_extension}'>\\1</a>"
"<a class='internal-link' href='#{site.baseurl}#{note_potentially_linked_to.url}#{link_extension}'>\\1</a>"
)
# Replace double-bracketed links using note filename
# [[cats]]
current_note.content = current_note.content.gsub(
/\[\[(#{title_from_filename})\]\]/i,
"<a class='internal-link' href='#{note_potentially_linked_to.url}#{link_extension}'>\\1</a>"
"<a class='internal-link' href='#{site.baseurl}#{note_potentially_linked_to.url}#{link_extension}'>\\1</a>"
)
end
@ -73,7 +73,7 @@ class BidirectionalLinksGenerator < Jekyll::Generator
# Nodes: Graph
graph_nodes << {
id: note_id_from_note(current_note),
path: "#{current_note.url}#{link_extension}",
path: "#{site.baseurl}#{current_note.url}#{link_extension}",
label: current_note.data['title'],
} unless current_note.path.include?('_notes/index.html')