Website/Rakefile

385 lines
11 KiB
Ruby

require "rubygems"
require "time"
require "net/http"
require "uri"
require "json"
$:.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 "ubreporting.rb"
require "bootstrap_markdown.rb"
require "disqus.rb"
require "ABET"
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
## Render 'talks' pages
for_files(/talks\/.*/) do
exclude_files(/talks\/index|talks\/graphics|talks\/ubodin/) do
extract_date_from_filename
create_collection("talks")
end
for_files(/talks\/index/) do
get_collection("talks").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
## Specialized Formatting
for_files(/demoday\/[0-9]{4}(sp|fa)\.html$/) do
add_dependency "db/demoday/2019fa.json"
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"
add_dependency "db/publications.json"
end
for_files(/^\/index.html$/) do
get_collection("news").map { |f| f[:in_path] }.each { |dep| add_dependency dep }
end
for_files(/teaching\/cse-562\/2018sp\/index.html/) do
add_dependency "db/teaching/cse4_562/2018sp/schedule.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
case `uname`.chomp
when "Darwin"
system("open build/index.html")
when "Linux"
system("xdg-open build/index.html &>/dev/null")
else
puts "Unknown platform #{`uname`}; Can't open"
end
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
cnp = NSFCnP.new("Oliver Kennedy",
$db["cv/okennedy/grants"].select { |r| r["status"] == "accepted" or r["status"] == "submitted" or r["status"] == "planned"}
)
cnp.render("artifacts/okennedy_current_pending.pdf")
cnp.print
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
files = Dir["artifacts/*.{pdf,json}"]
unless files.empty? then
system("cp -r #{files.join(" ")} build/artifacts/")
end
end
###################### Specialized Stuff for Individual Use ######################
file "okennedy_short.tex" => (["db/lab.json", "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,
general_service: 2015,
volunteering: 2015,
courses: 2015,
chair: 2017
},
skip: [
:invited_talks,
# :honors,
:reviewer,
:publications,
:contact,
:employment,
:memberships,
# :dept_service,
:tech_reports,
:general_service,
:reviewer,
# :publications,
:artifacts,
:grants
],
abbreviate: [
]
)
end
end
file "okennedy_short.pdf" => "okennedy_short.tex" do
system("pdflatex okennedy_short.tex")
end
file "okennedy_full.tex" => (["db/cv/okennedy.json", "lib/cv.rb", "Rakefile"]+Dir["db/cv/okennedy/**"]) do
File.open("okennedy_full.tex", "w+") do |fh|
CV.make("okennedy", fh,
title: "Curriculum Vitae (Long)",
include_pending_papers: true,
include_pending_grants: true,
include_rejected_grants: false,
include_blurb: true
)
end
end
file "okennedy_full.pdf" => "okennedy_full.tex" do
system("pdflatex okennedy_full.tex")
end
file "KennedyOliver-CV.tex" => (["db/cv/okennedy.json", "lib/cv.rb", "lib/ABET.rb", "Rakefile"]+Dir["db/cv/okennedy/**"]) do
File.open("KennedyOliver-CV.tex", "w+") do |fh|
ABET_CV.new(fh).gen
end
end
file "KennedyOliver-CV.pdf" => "KennedyOliver-CV.tex" do
system("pdflatex KennedyOliver-CV.tex")
end
task abet_cv: "KennedyOliver-CV.pdf"
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" => [ "Rakefile" ] do
File.open("artifacts/grant_report.txt", "w+") do |fh|
$db["publications"]
.map { |pub|
puts("Pub: "+pub.to_s)
pub.fetch("grants_cited", [])
.map { |grant|
puts(" `-> "+grant.to_s)
[ [
grant["agency"],
grant.fetch("agency_id", grant.fetch("project_name", "???"))
], pub
]
}
}.flatten(1)
.my_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"
task :ub_report do
UBSOE::generate_yearly_report(Time.now().year-1)
end
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
task "email-lab" do
members = $db["lab/members"].map do |name, data|
raise "No UBIT for #{name}" unless data.has_key? "ubit"
"#{name} <#{data["ubit"]}@buffalo.edu>"
end
puts members.join("\n")
# (system("open", "-a", "Mail", "mailto://#{members.join(", ")}"))
end
task :test do
puts ImageSmith::img("assets/people/oliver.jpg", bounding_box: [50,50], inline: true)
end
task :demoday do
uri = URI("https://demo.vizierdb.info/vizier-db/api/v1/projects/1be34a70/branches/b8c48b44/head")
outfile = "db/demoday/2019fa.json"
Net::HTTP.start(uri.host, uri.port, { :use_ssl => true }) do |http|
request = Net::HTTP::Get.new uri.path
request.basic_auth("mimir", "jormugundir")
response = http.request(request)
json = JSON.parse(response.body)
File.open(outfile, "w+") do |f|
f.puts(json["modules"][-1]["outputs"]["stdout"][0]["value"])
end
puts "Wrote to #{outfile}"
# p json["outputs"]#["stdout"]#[0]["value"]
end
end
file "artifacts/okennedy.bib" do
File.open("artifacts/okennedy.bib", "w+") do |fh|
LabMetadata.publications_for("Oliver Kennedy")
.each do |pub|
fh.puts LabMetadata.bibtex_for(pub)
end
end
end
file "artifacts/okennedy.ris" do
File.open("artifacts/okennedy.ris", "w+") do |fh|
LabMetadata.publications_for("Oliver Kennedy")
.filter do |pub|
case LabMetadata.complete_venue(pub)["type"]
when "demo", "panel" then false
else true
end
end
.each do |pub|
fh.puts LabMetadata.ris_for(pub)
end
end
end
task :bib => ["artifacts/okennedy.bib", "artifacts/okennedy.ris"]