From ee6d5ee9d2c70352ec341c58a1fe4ec801539cd4 Mon Sep 17 00:00:00 2001 From: ada Date: Fri, 22 Aug 2025 16:14:57 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20=D0=BF=D0=BB=D0=B0=D0=B3=D0=B8=D0=BD=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20=D0=B3=D0=B5=D0=BD=D0=B5=D1=80=D0=B0=D1=86=D0=B8=D0=B8?= =?UTF-8?q?=20=D0=B3=D1=80=D0=B0=D1=84=D0=B0=20=D0=B7=D0=B0=D0=BC=D0=B5?= =?UTF-8?q?=D1=82=D0=BE=D0=BA:=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D1=82?= =?UTF-8?q?=D1=8C=20=D1=84=D0=B0=D0=B9=D0=BB=20graph=5Fjson.rb=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D0=B2=D0=B8=D0=B7=D1=83=D0=B0=D0=BB=D0=B8=D0=B7?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D0=B8=20=D1=81=D0=B2=D1=8F=D0=B7=D0=B5=D0=B9?= =?UTF-8?q?=20=D0=BC=D0=B5=D0=B6=D0=B4=D1=83=20=D0=B7=D0=B0=D0=BC=D0=B5?= =?UTF-8?q?=D1=82=D0=BA=D0=B0=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _config.yml | 2 +- _plugins/graph_json.rb | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 _plugins/graph_json.rb 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