Add config to toggle html extension in links

This commit is contained in:
Maxime Vaillancourt
2021-01-26 08:32:07 -05:00
parent 5d190b6a97
commit 9232ce3ded
5 changed files with 15 additions and 7 deletions

View File

@@ -9,6 +9,8 @@ class BidirectionalLinksGenerator < Jekyll::Generator
all_docs = all_notes + all_pages
link_extension = !!site.config["use_html_extension"] ? '.html' : ''
# Convert all Wiki/Roam-style double-bracket link syntax to plain HTML
# anchor tag elements (<a>) with "internal-link" CSS class
all_docs.each do |current_note|
@@ -22,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}'>\\1</a>"
"<a class='internal-link' href='#{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}'>\\1</a>"
"<a class='internal-link' href='#{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}'>\\1</a>"
"<a class='internal-link' href='#{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}'>\\1</a>"
"<a class='internal-link' href='#{note_potentially_linked_to.url}#{link_extension}'>\\1</a>"
)
end
@@ -71,7 +73,7 @@ class BidirectionalLinksGenerator < Jekyll::Generator
# Nodes: Graph
graph_nodes << {
id: note_id_from_note(current_note),
path: current_note.url,
path: "#{current_note.url}#{link_extension}",
label: current_note.data['title'],
} unless current_note.path.include?('_notes/index.html')