Website/Rakefile

245 lines
6.7 KiB
Ruby

require "rubygems"
$:.push "lib"
require "gemsmith.rb"
require "jdb.rb"
require "lab_metadata.rb"
require "util.rb"
require "cv.rb"
require "nsfcp.rb"
require "nsfconflicts.rb"
require "bootstrap_markdown.rb"
require "disqus.rb"
include GemSmith
$db = JDB.new("db")
$cv_users = ["okennedy"]
LabMetadata::build_people_metadata()
site :odin_lab, out: "build" do
## Splice off header information
for_files(/((\.erb)|(\.md)|(\.html))$/) do
exclude_files(/^\/?(slides)\//) do
extract_headers
end
end
## Render specialized formats
for_files(/\.md$/) do
render_markdown(BootstrapMarkdown.new,
tables: true,
disable_indented_code_blocks: true,
fenced_code_blocks: true,
autolink: true,
no_intra_emphasis: true
)
end
for_files(/\.erb$/) do
render_erb
end
## Generate pages for each lab member
LabMetadata::create_people_pages
for_files(/people\/.*\.html$/) do
exclude_files(/index\.html/) do
apply_template("templates/person.erb")
end
end
## Render 'news' pages
for_files(/rants\/.*\.html$/) do
exclude_files(/index\.html$/) do
extract_date_from_filename
create_collection("rants")
apply { |f| f[:news_prev] = f[:rants_prev]; f[:news_next] = f[:rants_next] }
apply_template("templates/news.erb")
end
for_files(/index\.html$/) do
get_collection("rants").map { |f| f[:in_path] }.each { |dep| add_dependency dep }
end
end
for_files(/news\/.*\.html$/) do
exclude_files(/index\.html$/) do
extract_date_from_filename
create_collection("news")
apply_template("templates/news.erb")
end
for_files(/index\.html$/) do
get_collection("news").map { |f| f[:in_path] }.each { |dep| add_dependency dep }
end
end
## Specialized Formatting
for_files(/seminar\/[0-9]{4}(sp|fa)\.html$/) do
apply {|f| f[:extraCSS] = [{ "asset" => "seminar.css" }] }
apply_template("templates/seminar.erb")
end
## Apply templating
for_files(/\.html$/) do
exclude_files(/^\/?(slides)\//) do
exclude_files(/^\/?teaching\/.*\/?(slides)\/.*\.html/) do
apply_template("templates/lab.erb")
end
end
end
## Specify specialized dependencies (e.g., on the database)
for_files(/people\/.*\.html$/) do
add_dependency "db/lab.json"
add_dependency "db/publications.json"
end
for_files(/grants\/index\.html/) do
add_dependency "db/cv/okennedy/grants.json"
add_dependency "db/lab.json"
end
for_files(/papers\/index.html/) do
add_dependency "db/publications.json"
add_dependency "db/lab.json"
add_dependency "lib/publication.erb"
end
for_files(/research\/.*\/index.html/) do
add_dependency "db/lab.json"
end
## Static assets
add_assets([
"bootstrap", "jquery.js", "mathjax",
"odin.css", "seminar.css",
"logos", "favicon", "people", "photos"
])
add_static("slides", "slides")
## Sub-sites
add_static("subsites/nmeneghetti", "people/niccolo_meneghetti")
end
task :default => [ :odin_lab ]
task :open => :default do
system("open build/index.html")
end
task :clean do
system("rm -r build")
end
directory "artifacts"
$cv_users.each do |who|
file "artifacts/#{who}.tex" => (["artifacts", "db/cv/#{who}.json", "lib/cv.rb", "Rakefile"]+Dir["db/cv/#{who}/**"]) do
File.open("artifacts/#{who}.tex", "w+") do |fh|
CV.make(who, fh)
end
end
file "artifacts/#{who}.pdf" => "artifacts/#{who}.tex" do
system("cd artifacts; pdflatex #{who}.tex")
end
task :cv => "artifacts/#{who}.pdf"
end
file "artifacts/okennedy_current_and_pending.pdf" do
NSFCnP.new("Oliver Kennedy",
$db["cv/okennedy/grants"].select { |r| r["status"] == "accepted" or r["status"] == "submitted" or r["status"] == "planned"}
).render("artifacts/okennedy_current_pending.pdf")
end
task :cnp => "artifacts/okennedy_current_and_pending.pdf"
file "artifacts/db.json" => "artifacts" do
File.open("artifacts/db.json", "w+") do |f|
f.puts JSON.generate($db.data)
end
end
task :documents => ["artifacts/db.json", :cv, :cnp]
directory "build/artifacts"
task :deploy => [:documents,:odin_lab,"build/artifacts"] do
system("cp -r artifacts/*.{pdf,json} build/artifacts/")
end
###################### Specialized Stuff for Individual Use ######################
file "okennedy_short.tex" => (["db/cv/okennedy.json", "lib/cv.rb", "Rakefile"]+Dir["db/cv/okennedy/**"]) do
File.open("okennedy_short.tex", "w+") do |fh|
CV.make("okennedy", fh,
title: "Recent Activities",
since: {
education: 2008,
reviewer: 2015,
general_service: 2015,
volunteering: 2015,
talks: 2015,
courses: 2015,
publications: 2014
},
skip: [
:employment,
:memberships,
:dept_service,
:tech_reports
]
)
end
end
file "okennedy_short.pdf" => "okennedy_short.tex" do
system("pdflatex okennedy_short.tex")
end
file "artifacts/okennedy_collaborators.txt" => ($db.files + ["lib/nsfconflicts.rb"]) do
NSFConflicts.new("Oliver Kennedy", $db).
render("artifacts/okennedy_collaborators.txt")
end
task :collab => "artifacts/okennedy_collaborators.txt"
task :conflicts => "artifacts/okennedy_collaborators.txt"
["mimir", "insider-threats", "astral"].each do |project|
file "artifacts/#{project}_papers.txt" => [ $db.files, "artifacts", "Rakefile" ].flatten do
File.open("artifacts/#{project}_papers.txt", "w+") do |fh|
fh.puts $db["publications"].
where { |pub| pub.fetch("projects", []).include? project }.
map { |pub| LabMetadata::format_pub_for_report(pub) }.
compact.
join("\n\n")
end
end
task :projectreport => "artifacts/#{project}_papers.txt"
end
task :report => :projectreport
file "artifacts/grant_report.txt" do
File.open("artifacts/grant_report.txt", "w+") do |fh|
$db["publications"]
.map { |pub|
pub.fetch("grants_cited", [])
.map { |grant|
[ [
grant["agency"],
grant.fetch("agency_id", grant.fetch("project_name", "???"))
], pub
]
}
}.flatten(1)
.reduce
.each { |grant, pubs|
fh.puts grant[0]+"/"+grant[1]
fh.puts "-----------"
pubs.each { |pub|
pub = LabMetadata::format_pub_for_report(pub)
fh.puts "\n"+pub unless pub.nil?
}
fh.puts "\n\n"
}
end
end
task :report => "artifacts/grant_report.txt"
file "artifacts/nsf_merit_blurb.txt" => [ $db.files, "artifacts", "Rakefile" ].flatten do
# File.open("artifacts/nsf_related_blurb.txt", "w+") do |fh|
citable_pubs =
$db["publications"]
.where { |pub| pub.fetch("grants_cited", []).index { |grant| /NSF/ =~ grant.fetch("agency", "") } }
citable_pubs.each { |pub| puts pub["title"] }
# end
end