diff --git a/_config.yml b/_config.yml index b5f2fba..d061050 100644 --- a/_config.yml +++ b/_config.yml @@ -94,7 +94,7 @@ obsidian: slugify: true # заменять пробелы/кириллицу на слаг ext: ".md" attachments_dir: "assets/cache/" - graph: true + # graph: true # --- Навигация (подключим _data/navigation.yml) --- navigation: diff --git a/_plugins/graph_json.rb b/_plugins/graph_json.rb new file mode 100644 index 0000000..a71584b --- /dev/null +++ b/_plugins/graph_json.rb @@ -0,0 +1,22 @@ +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