2022-03-10 01:29:52 -08:00
|
|
|
require "pathname"
|
|
|
|
require "set"
|
|
|
|
require "json"
|
|
|
|
|
|
|
|
def resolve_path(bp, p)
|
|
|
|
path = nil
|
|
|
|
if bp.start_with? "."
|
|
|
|
path = Pathname.new(File.join(bp, p)).cleanpath.to_s
|
|
|
|
elsif p.start_with? "blog/"
|
|
|
|
path = File.join("content", p)
|
|
|
|
else
|
|
|
|
path = File.join("content", "blog", p)
|
|
|
|
end
|
|
|
|
if File.directory? path
|
|
|
|
path = File.join(path, "index.md")
|
|
|
|
elsif !path.end_with? ".md"
|
|
|
|
path += ".md"
|
|
|
|
end
|
|
|
|
path.gsub("blog/blog/", "blog/")
|
|
|
|
end
|
|
|
|
|
|
|
|
files = Set.new
|
|
|
|
refs = {}
|
2022-03-15 15:08:46 -07:00
|
|
|
Dir['content/blog/**/*.md'].each do |file|
|
2022-03-10 01:29:52 -08:00
|
|
|
file = file.chomp
|
|
|
|
files << file
|
|
|
|
arr = refs[file] || (refs[file] = [])
|
|
|
|
File.open(file).read.scan(/< relref "([^"]+)" >/) do |ref|
|
|
|
|
ref = resolve_path(File.dirname(file), ref[0])
|
|
|
|
arr << ref
|
|
|
|
files << ref
|
|
|
|
end
|
|
|
|
arr.uniq!
|
|
|
|
end
|
|
|
|
|
|
|
|
data = {}
|
|
|
|
id = 0
|
2024-05-30 20:52:14 -07:00
|
|
|
series = {}
|
2022-03-10 01:29:52 -08:00
|
|
|
files.each do |file|
|
|
|
|
id += 1
|
|
|
|
name = file
|
|
|
|
tags = []
|
|
|
|
group = 1
|
2022-03-15 17:10:00 -07:00
|
|
|
draft = false
|
2022-04-09 03:24:15 -07:00
|
|
|
next unless File.exists?(file)
|
2022-03-10 01:29:52 -08:00
|
|
|
value = File.size(file)
|
|
|
|
url = file.gsub(/^content/, "https://danilafe.com").delete_suffix("/index.md").delete_suffix(".md")
|
|
|
|
File.readlines(file).each do |l|
|
|
|
|
if l =~ /^title: (.+)$/
|
|
|
|
name = $~[1].delete_prefix('"').delete_suffix('"')
|
2022-03-15 17:10:00 -07:00
|
|
|
elsif l =~ /^draft: true$/
|
|
|
|
draft = true
|
2024-05-30 20:52:14 -07:00
|
|
|
elsif l =~ /^series: (.+)$/
|
|
|
|
this_series = $~[1]
|
|
|
|
series_list = series.fetch(this_series) do
|
|
|
|
series[this_series] = []
|
|
|
|
end
|
|
|
|
series_list << file
|
2022-03-10 01:29:52 -08:00
|
|
|
elsif l =~ /^tags: (.+)$/
|
|
|
|
tags = $~[1].delete_prefix("[").delete_suffix("]").split(/,\s?/).map { |it| it.gsub('"', '') }
|
|
|
|
if tags.include? "Compilers"
|
|
|
|
group = 2
|
|
|
|
elsif tags.include? "Coq"
|
|
|
|
group = 3
|
|
|
|
elsif tags.include? "Programming Languages"
|
|
|
|
group = 4
|
|
|
|
elsif tags.include? "Haskell"
|
|
|
|
group = 5
|
|
|
|
elsif tags.include? "Crystal"
|
|
|
|
group = 6
|
2024-05-30 00:38:27 -07:00
|
|
|
elsif tags.include? "Agda"
|
|
|
|
group = 7
|
|
|
|
elsif tags.include? "Hugo"
|
|
|
|
group = 8
|
2022-03-10 01:29:52 -08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2022-03-15 17:10:00 -07:00
|
|
|
next if draft
|
|
|
|
data[file] = { :id => id, :name => name, :group => group, :tags => tags, :url => url, :value => value }
|
2022-03-10 01:29:52 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
edges = []
|
|
|
|
files.each do |file1|
|
|
|
|
# files.each do |file2|
|
|
|
|
# next if file1 == file2
|
|
|
|
# next unless data[file1][:tags].any? { |t| data[file2][:tags].include? t }
|
|
|
|
# edges << { :from => data[file1][:id], :to => data[file2][:id] }
|
|
|
|
# end
|
|
|
|
next unless frefs = refs[file1]
|
|
|
|
frefs.each do |ref|
|
2022-03-15 17:10:00 -07:00
|
|
|
next unless data[file1]
|
|
|
|
next unless data[ref]
|
2022-03-10 01:29:52 -08:00
|
|
|
edges << { :from => data[file1][:id], :to => data[ref][:id] }
|
|
|
|
end
|
|
|
|
end
|
2024-05-30 20:52:14 -07:00
|
|
|
series.each do |series, files|
|
|
|
|
files.sort.each_cons(2) do |file1, file2|
|
|
|
|
next unless data[file1]
|
|
|
|
next unless data[file2]
|
|
|
|
edges << { :from => data[file1][:id], :to => data[file2][:id] }
|
|
|
|
edges << { :from => data[file2][:id], :to => data[file1][:id] }
|
|
|
|
end
|
|
|
|
end
|
2024-05-30 20:58:03 -07:00
|
|
|
edges.uniq!
|
2022-03-10 01:29:52 -08:00
|
|
|
# edges.filter! { |e| e[:from] < e[:to] }
|
2024-05-30 21:07:23 -07:00
|
|
|
edges.map! { |e| { :from => [e[:from], e[:to]].min, :to => [e[:from], e[:to]].max } }.uniq!
|
2022-03-10 01:29:52 -08:00
|
|
|
|
2022-03-15 15:08:46 -07:00
|
|
|
puts ("export const nodes = " + JSON.pretty_unparse(data.values) + ";")
|
|
|
|
puts ("export const edges = " + JSON.pretty_unparse(edges) + ";")
|