Add notes graph visualization
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user