180 lines
4.3 KiB
JavaScript
180 lines
4.3 KiB
JavaScript
var extname = require('path').extname;
|
|
var Metalsmith = require('metalsmith');
|
|
var drafts = require('metalsmith-drafts');
|
|
var markdown = require('metalsmith-markdown');
|
|
var layouts = require('metalsmith-layouts');
|
|
var inplace = require('metalsmith-in-place');
|
|
var uglify = require('metalsmith-uglify');
|
|
var rename = require('metalsmith-rename');
|
|
var metadata = require('metalsmith-metadata');
|
|
var fingerprint = require('metalsmith-fingerprint');
|
|
var branch = require('metalsmith-branch');
|
|
var assets = require('metalsmith-assets');
|
|
var paths = require('metalsmith-paths');
|
|
var linkchecker = require('metalsmith-broken-link-checker');
|
|
var rootpath = require('metalsmith-rootpath');
|
|
var mjAPI = require("mathjax-node/lib/mj-page.js");
|
|
var collections = require('metalsmith-collections');
|
|
var filenamedate = require('metalsmith-date-in-filename');
|
|
|
|
|
|
/**
|
|
* Helpers
|
|
*/
|
|
|
|
var buildPubs = function(files, smith, done){
|
|
var lab = smith.metadata().odinLab.members.concat(
|
|
smith.metadata().odinLab.alumni);
|
|
var pubs = smith.metadata().okennedy.data.publications.concat(
|
|
smith.metadata().altPubs);
|
|
var venues = smith.metadata().okennedy.venues;
|
|
var pubsByYear = {}
|
|
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(function(author) {
|
|
if(lab.findIndex(function(member, idx, ignore) { return author == member }) >= 0) {
|
|
return "<span class='lab_member'>"+author.replace(/ /, " ")+"</span>"
|
|
} else {
|
|
return author.replace(/ /, " ")
|
|
}
|
|
})
|
|
.join(", ")
|
|
if(typeof pub.year == 'undefined'){
|
|
console.log(pub);
|
|
throw "Unknown year for "+pub
|
|
}
|
|
|
|
if(typeof pubsByYear[pub.year] == 'undefined') {
|
|
pubsByYear[pub.year] = []
|
|
}
|
|
|
|
var resourcesFormat = ""
|
|
if(typeof pub.urls == 'object') {
|
|
var resources = []
|
|
for(cat in pub.urls){
|
|
resources.push("<a href="+pub.urls[cat]+">"+cat+"</a>")
|
|
}
|
|
resourcesFormat = "( "+resources.join(" | ")+" )";
|
|
}
|
|
|
|
pubsByYear[pub.year].push(
|
|
{
|
|
title: pub.title,
|
|
authorFormat: authorFormat,
|
|
authors: pub.authors,
|
|
venue: pub.venue+" "+pub.year,
|
|
resourcesFormat: resourcesFormat
|
|
}
|
|
)
|
|
}
|
|
var out = []
|
|
for(i in pubsByYear) {
|
|
out.push({year: i, pubs: pubsByYear[i]})
|
|
}
|
|
// console.log(out)
|
|
smith.metadata()["allpubs"] = out.reverse()
|
|
done()
|
|
}
|
|
|
|
|
|
var renderOneTex = function(file, cnt)
|
|
{
|
|
// console.log(file)
|
|
mjAPI.typeset({
|
|
html: file.contents,
|
|
renderer: "NativeMML",
|
|
inputs: ["TeX"],
|
|
xmlns: "mml",
|
|
singleDollars: true
|
|
}, function(result) {
|
|
"use strict";
|
|
file.contents = new Buffer(result.html)
|
|
cnt.count --;
|
|
if(cnt.count <= 0){ cnt.done() }
|
|
});
|
|
|
|
}
|
|
|
|
mjAPI.start();
|
|
|
|
var renderTeX = function(files, smith, done)
|
|
{
|
|
var cnt = { count: 1, done: done };
|
|
for(f in files){
|
|
cnt.count ++;
|
|
renderOneTex(files[f], cnt);
|
|
}
|
|
cnt.count --;
|
|
if(cnt.count <= 0){ cnt.done() }
|
|
}
|
|
|
|
|
|
/**
|
|
* Build.
|
|
*/
|
|
|
|
var metalsmith = Metalsmith(__dirname)
|
|
.source('./src')
|
|
.destination('./site')
|
|
.use(drafts())
|
|
.use(fingerprint({
|
|
pattern: 'css/*.css'
|
|
}))
|
|
.use(metadata({
|
|
okennedy: "metadata/okennedy.json",
|
|
odinLab: "metadata/lab.json",
|
|
altPubs: "metadata/publications.json",
|
|
}))
|
|
.use(buildPubs)
|
|
.use(rootpath())
|
|
.use(inplace({
|
|
engine: "handlebars"
|
|
}))
|
|
.use(filenamedate(false))
|
|
.use(markdown({
|
|
pattern: "**/*.md"
|
|
}))
|
|
.use(paths({
|
|
property: "paths"
|
|
}))
|
|
.use(collections({
|
|
news: {
|
|
pattern: 'news/*.html',
|
|
sortBy: 'date',
|
|
reverse: true,
|
|
limit: 5
|
|
},
|
|
rants: {
|
|
pattern: 'rants/*.html',
|
|
sortBy: 'date',
|
|
reverse: true,
|
|
limit: 3
|
|
}
|
|
}))
|
|
.use(function(x,y,z){console.log(y.metadata().news); z()})
|
|
.use(branch()
|
|
.pattern('**/*.html')
|
|
.use(renderTeX)
|
|
.use(layouts({
|
|
engine: "handlebars",
|
|
default: "default.hbs"
|
|
}))
|
|
)
|
|
.use(linkchecker({
|
|
allowRegex: /^(\/resources|\/slides)/,
|
|
allowRedirect: true
|
|
}))
|
|
// .use(uglify())
|
|
.build(function(err){
|
|
if (err) throw err;
|
|
});
|
|
|