16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/jekyll/obsidian.rb', line 16
def generate(site)
vault = site.config["obsidian_vault"] || site.source
if vault.nil?
puts "Error: obsidian_vault is not set in config.yml"
exit(1)
end
enable_backlinks = site.config["obsidian_backlinks"]
enable_embeds = site.config["obsidian_embeds"]
data_dir = File.join(File.dirname(site.dest), "_data", "obsidian")
FileUtils.mkdir_p(data_dir) unless File.directory?(data_dir)
site.data["obsidian"] = {} unless site.data["obsidian"]
counts = {dirs: 0, files: 0, size: 0}
obsidian_files = collect_files(vault, "", counts)
vault_data_json = File.join(data_dir, "vault_data.json")
File.write(vault_data_json, JSON.pretty_generate(counts.to_json))
vault_files_json = File.join(data_dir, "vault_files.json")
File.write(vault_files_json, JSON.pretty_generate(obsidian_files.to_json))
backlinks, embeds = build_links(vault, obsidian_files, obsidian_files)
if enable_backlinks || enable_backlinks.nil?
backlinks_json = File.join(data_dir, "backlinks.json")
File.write(backlinks_json, escape_backlinks(backlinks))
puts "Backlinks built."
else
puts "Backlinks disabled"
end
if enable_embeds || enable_embeds.nil?
embeds_json = File.join(data_dir, "embeds.json")
File.write(embeds_json, escape_embeds(embeds))
puts "Embeds built."
else
puts "Embeds disabled"
end
site.config["obsidian_homepage"]
obsidian_dir = File.join(File.dirname(site.dest), "_includes", "obsidian")
FileUtils.mkdir_p(obsidian_dir) unless File.directory?(obsidian_dir)
layouts_dir = File.join(File.dirname(site.dest), "_layouts")
FileUtils.mkdir_p(layouts_dir) unless File.directory?(layouts_dir)
scss_dir = File.join(File.dirname(site.dest), "assets", "obsidian")
FileUtils.mkdir_p(scss_dir) unless File.directory?(scss_dir)
partials_dir = File.join(File.dirname(site.dest), "_sass", "obsidian")
FileUtils.mkdir_p(partials_dir) unless File.directory?(partials_dir)
project_root = File.expand_path("../..", File.dirname(__FILE__))
plugin_dir = File.join(project_root, "assets")
main_scss = File.join(plugin_dir, "css", "obsidian.scss")
copy_file_to_dir(main_scss, scss_dir)
copy_files_from_dir(File.join(plugin_dir, "css", "partials"), partials_dir)
layout = File.join(plugin_dir, "layouts", "obsidian.html")
copy_file_to_dir(layout, layouts_dir, true)
copy_files_from_dir(File.join(plugin_dir, "includes"), obsidian_dir, true)
end
|