mirror of
https://github.com/ada-dmitry/ada-dmitry.github.io.git
synced 2026-09-24 01:10:35 +00:00
23 lines
692 B
Ruby
23 lines
692 B
Ruby
require 'json'
|
|
|
|
Jekyll::Hooks.register :site, :post_write do |site|
|
|
notes = site.collections["notes"].docs
|
|
nodes = []
|
|
edges = []
|
|
|
|
notes.each do |note|
|
|
id = note.url
|
|
nodes << { id: id, title: note.data["title"] || note.basename_without_ext, url: note.url }
|
|
|
|
# ищем [[ссылки]]
|
|
note.content.scan(/\[\[(.*?)\]\]/).each do |m|
|
|
target = m[0].downcase.strip.gsub(" ", "-")
|
|
target_doc = notes.find { |n| n.basename_without_ext.downcase == target }
|
|
edges << { source: id, target: target_doc.url } if target_doc
|
|
end
|
|
end
|
|
|
|
graph = { nodes: nodes, edges: edges }
|
|
File.write(File.join(site.dest, "graph.json"), JSON.pretty_generate(graph))
|
|
end
|