From e0005f58ba50ab67f10e5a804cd09a3ee9795348 Mon Sep 17 00:00:00 2001 From: Maxime Vaillancourt Date: Tue, 21 Jul 2020 21:26:28 -0400 Subject: [PATCH] Add notes graph visualization --- _includes/notes_graph.html | 196 ++++++++++++++++++++++ _layouts/note.html | 5 + _pages/index.md | 4 + _plugins/bidirectional_links_generator.rb | 29 ++++ 4 files changed, 234 insertions(+) create mode 100644 _includes/notes_graph.html diff --git a/_includes/notes_graph.html b/_includes/notes_graph.html new file mode 100644 index 0000000..48fd09a --- /dev/null +++ b/_includes/notes_graph.html @@ -0,0 +1,196 @@ + + + + +
+ +
diff --git a/_layouts/note.html b/_layouts/note.html index 0d04671..26a9f3e 100644 --- a/_layouts/note.html +++ b/_layouts/note.html @@ -39,3 +39,8 @@ layout: default +
+ +

Here are all the notes in this garden, along with their links, visualized as a graph.

+ +{% include notes_graph.html %} diff --git a/_pages/index.md b/_pages/index.md index 0e2396b..b2ffcca 100644 --- a/_pages/index.md +++ b/_pages/index.md @@ -8,3 +8,7 @@ permalink: / # Welcome! 🌱 This is your digital garden. Here's [[Your first seed]] to get started on your exploration. + +

Here are all the notes in this garden, along with their links, visualized as a graph.

+ +{% include notes_graph.html %} diff --git a/_plugins/bidirectional_links_generator.rb b/_plugins/bidirectional_links_generator.rb index f6a5a65..87b9fce 100644 --- a/_plugins/bidirectional_links_generator.rb +++ b/_plugins/bidirectional_links_generator.rb @@ -1,6 +1,9 @@ # frozen_string_literal: true class BidirectionalLinksGenerator < Jekyll::Generator def generate(site) + graph_nodes = [] + graph_edges = [] + all_notes = site.collections['notes'].docs all_pages = site.pages @@ -19,11 +22,37 @@ class BidirectionalLinksGenerator < Jekyll::Generator # Identify note backlinks and add them to each note all_notes.each do |current_note| + # Nodes: Jekyll notes_linking_to_current_note = all_notes.filter do |e| e.content.include?(current_note.url) end + # Nodes: Graph + graph_nodes << { + id: note_id_from_note(current_note), + path: current_note.url, + label: current_note.title, + } unless current_note.path.include?('_notes/index.html') + + # Edges: Jekyll current_note.data['backlinks'] = notes_linking_to_current_note + + # Edges: Graph + notes_linking_to_current_note.each do |n| + graph_edges << { + source: note_id_from_note(n), + target: note_id_from_note(current_note), + } + end end + + File.write('_includes/notes_graph.json', JSON.dump({ + edges: graph_edges, + nodes: graph_nodes, + })) + end + + def note_id_from_note(note) + note.title.to_i(36).to_s end end