-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRakefile
67 lines (55 loc) · 2.05 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
require "rake"
require "rake/clean"
require "json"
task default: :jekyll
RANKS = %w[class subclass infraclass megacohort supercohort cohort subcohort infracohort section subsection division subdivision series superorder order suborder infraorder family]
def make_taxonomy_api(rank)
outfn = "_data/taxonomy/#{rank}.json"
file = File.read outfn
json = JSON.parse(file)
jspath = "api/taxonomy/#{rank}"
FileUtils.mkdir_p jspath
FileUtils.cp outfn, "api/taxonomy"
json.each do |key, value|
File.open("#{jspath}/#{key}.json", "w") { |f| f.write(JSON.pretty_generate(value)) }
end
end
def make_taxonomy_md(rank)
outfn = "_data/taxonomy/#{rank}.json"
file = File.read outfn
json = JSON.parse(file)
mdpath = "_#{rank}"
FileUtils.mkdir_p mdpath
json.each do |key, value|
File.open("#{mdpath}/#{key}.md", "w") do |f|
f.write("---\n")
f.write("title: '#{key}'\n")
f.write("description: 'Taxonomy and phylogeny of #{key}, a #{rank} of ray-finned fishes. Based on the Phylogenetic Fish Classification. Also includes species checklists, fossil calibrations, DNA sequences.'\n")
f.write("---\n")
end
end
end
rule ( %r{api/taxonomy/.+} ) => [
proc {|task_name| task_name.sub('api', '_data').concat('.json') }
] do |t|
make_taxonomy_api(File.basename(t.name))
end
rule ( %r{_(#{RANKS.join("|")})} ) => [
proc {|task_name| task_name.sub("_", "_data/taxonomy/").concat(".json") }
] do |t|
make_taxonomy_md(t.name.sub("_", ""))
end
task :taxonomy_api => (RANKS.map {|r| "api/taxonomy/#{r}"})
task :taxonomy_md => (RANKS.map {|r| "_#{r}"})
task :taxonomy => [:taxonomy_api, :taxonomy_md]
task :deps => [:taxonomy]
task jekyll: :deps do
sh "bundle", "exec", "jekyll", "build"
end
task serve: :deps do
sh "bundle", "exec", "jekyll", "serve", "--incremental"
end
task serve2: :deps do
sh "bundle", "exec", "jekyll", "serve"
end
CLEAN.include FileList["_site", '_data/taxonomy/', '_data/monophyly', '_family', '_order', 'downloads/taxonomy', 'api/taxonomy']