Website/old/stages/build-pubs.js

98 lines
2.9 KiB
JavaScript

module.exports = plugin;
var formatAuthor = require("../lib/format-name.js");
var push = function(arr, key, elem)
{
if(typeof arr[key] == 'undefined') { arr[key] = [] }
arr[key].push(elem)
}
function plugin() {
return function (files, smith, done){
var lab = smith.metadata().labMembers;
var pubs = smith.metadata().okennedy.data.publications.concat(
smith.metadata().altPubs);
var venues = smith.metadata().okennedy.venues;
var pubsByYear = {}
var pubsByProject = {}
for(i in pubs){
var pub = pubs[i]
var venue = venues[pub.venue] || {}
if(pub.type == "patent"){ continue; }
if(venue.type == "techreport") {
if(pub.venue != "ArXiv"){ continue; }
}
var authorFormat =
pub.authors
.map(formatAuthor(lab))
.join(", ")
if(typeof pub.year == 'undefined'){
console.log(pub);
throw "Unknown year for "+pub
}
var resourcesFormat = ""
if(typeof pub.urls == 'object') {
var resources = []
for(cat in pub.urls){
resources.push("<a href="+pub.urls[cat]+">"+cat+"</a>")
}
resourcesFormat = "(&nbsp;"+resources.join("&nbsp;|&nbsp;")+"&nbsp;)";
}
var venue = pub.venue;
// console.log(pub);
if(typeof pub.track != 'undefined'){
venue = venue+"-"+pub.track.toUpperCase();
}
venue = venue+" "+pub.year
var pubMeta =
{
title: pub.title,
visible: !(pub.hidden || false),
authorFormat: authorFormat,
authors: pub.authors,
venue: venue,
resourcesFormat: resourcesFormat,
projects: pub.projects
}
// console.log(pubMeta)
// Associate the publication with its year, but only if not hidden
push(pubsByYear, pub.year, pubMeta)
// Associate the publication with each of its authors if they're lab
// members
for(i in pub.authors){
var author = pub.authors[i]
// console.log("affiliating " +pub.title+" with "+author)
// console.log(smith.metadata().odinLab.members[author])
if(typeof smith.metadata().odinLab.members[author] != 'undefined'){
if(typeof smith.metadata().odinLab.members[author].pubs == 'undefined'){
smith.metadata().odinLab.members[author].pubs = [pubMeta]
} else {
smith.metadata().odinLab.members[author].pubs.push(pubMeta)
}
}
}
// Associate the publication with each of its projects
for(p in pub.projects){
// console.log("Associating "+pubMeta.title+" with "+pub.projects[p])
push(pubsByProject, pub.projects[p], pubMeta)
}
}
var out = []
for(i in pubsByYear) {
out.push({year: i, pubs: pubsByYear[i]})
}
// console.log(out)
smith.metadata()["allpubs"] = out.reverse()
// console.log(pubsByProject)
smith.metadata()["projectPubs"] = pubsByProject
done()
}
}