mirror of
https://github.com/ada-dmitry/ada-dmitry.github.io.git
synced 2026-09-24 01:10:35 +00:00
Удалить устаревшие файлы графа заметок: _pages/graph.md и _plugins/note_graph.rb
This commit is contained in:
@@ -1,34 +0,0 @@
|
||||
---
|
||||
layout: single
|
||||
title: "Граф заметок"
|
||||
permalink: /graph/
|
||||
---
|
||||
|
||||
<div id="graph" style="height:70vh"></div>
|
||||
|
||||
<script src="https://unpkg.com/force-graph"></script>
|
||||
<script>
|
||||
fetch('{{ "/assets/js/graph-data.json" | relative_url }}')
|
||||
.then(r => r.json())
|
||||
.then(data => {
|
||||
const el = document.getElementById('graph');
|
||||
const Graph = ForceGraph()(el)
|
||||
.graphData(data)
|
||||
.nodeId('id')
|
||||
.nodeLabel(n => n.title)
|
||||
.nodeAutoColorBy('group')
|
||||
.backgroundColor(getComputedStyle(document.body).backgroundColor || '#111')
|
||||
.linkColor(() => 'rgba(173,216,230,0.6)')
|
||||
.linkDirectionalParticles(2)
|
||||
.linkDirectionalParticleSpeed(0.004)
|
||||
.onNodeClick(n => window.location = n.url);
|
||||
|
||||
// чуть уменьшить размеры узлов/шрифтов для тёмной темы
|
||||
Graph.nodeRelSize(6);
|
||||
});
|
||||
</script>
|
||||
|
||||
<style>
|
||||
#note-graph { height: 70vh; min-height: 420px; }
|
||||
</style>
|
||||
<div id="note-graph"></div>
|
||||
@@ -1,39 +0,0 @@
|
||||
# _plugins/note_graph.rb
|
||||
require "json"
|
||||
require "fileutils"
|
||||
|
||||
module NoteGraph
|
||||
class Generator < Jekyll::Generator
|
||||
safe true
|
||||
priority :low
|
||||
|
||||
def generate(site)
|
||||
notes = (site.collections["notes"]&.docs) || []
|
||||
|
||||
nodes = []
|
||||
links = []
|
||||
|
||||
notes.each do |doc|
|
||||
title = (doc.data["title"] || doc.basename_without_ext).to_s
|
||||
nodes << { id: title, url: doc.url }
|
||||
|
||||
# [[Note]] / [[Note|alias]] / [[Note#Heading]] / [[Note#Heading|alias]]
|
||||
doc.content.to_s.scan(/\[\[([^\]|#]+)(?:#[^\]]*)?(?:\|[^\]]+)?\]\]/).flatten.each do |raw|
|
||||
target = raw.strip
|
||||
links << { source: title, target: target }
|
||||
end
|
||||
end
|
||||
|
||||
graph = { nodes: nodes.uniq, links: links }
|
||||
site.config["note_graph_json"] = JSON.pretty_generate(graph)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Пишем файл ПОСЛЕ сборки сайта
|
||||
Jekyll::Hooks.register :site, :post_write do |site|
|
||||
data = site.config["note_graph_json"] || "{}"
|
||||
out_path = File.join(site.dest, "assets", "js", "graph-data.json")
|
||||
FileUtils.mkdir_p(File.dirname(out_path))
|
||||
File.write(out_path, data)
|
||||
end
|
||||
Reference in New Issue
Block a user