Website/Rakefile
2017-08-25 10:10:48 -04:00

224 lines
6.2 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"
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"
file "artifacts/oracle_papers.txt" => [ $db.files, "artifacts", "Rakefile" ].flatten do
File.open("artifacts/oracle_papers.txt", "w+") do |fh|
fh.puts $db["publications"].
where { |pub| pub.fetch("projects", []).include? "mimir" }.
map { |pub|
pub = LabMetadata::complete_venue(pub)
case pub["type"]
when "conference", "journal", "workshop", "abstract" then
[ pub["title"],
pub["authors"].join(", "),
"#{LabMetadata::venue_name(pub, size: :full_parens)} #{pub["year"]}",
pub["urls"].map { |k,v| "#{k.capitalize}: #{v}" },
LabMetadata.bibtex_for(pub).split("\n")
].flatten
when "thesis" then
[ pub["title"],
pub["authors"].join(", "),
"Thesis #{pub["degree"]} #{pub["year"]}",
pub["urls"].map { |k,v| "#{k.capitalize}: #{v}" },
LabMetadata.bibtex_for(pub).split("\n")
].flatten
else nil
end
}.
compact.
map { |record| "> #{record.join("\n ")}" }.
join("\n\n")
end
end