summaryrefslogtreecommitdiff
path: root/webserver.js
diff options
context:
space:
mode:
Diffstat (limited to 'webserver.js')
-rwxr-xr-xwebserver.js70
1 files changed, 69 insertions, 1 deletions
diff --git a/webserver.js b/webserver.js
index f867c74..6b3a172 100755
--- a/webserver.js
+++ b/webserver.js
@@ -92,6 +92,68 @@ for (let i = 0; i < module_list.length; i++) {
}
+function padLeft(s, len, fill) {
+ let prefix = "";
+ const num = len - s.length;
+ for (let i = 0; i < num; i++) prefix += fill;
+ return prefix + s;
+}
+
+function buildPublicationsHTML(info) {
+ let res = "";
+ for (const obj of info.pubs) {
+ if (res.length != 0) res += "\n\t\t\t";
+
+ res += "<li>";
+ res += obj.year;
+ if ("month" in obj) res += "-" + padLeft(obj.month + "", 2, "0")
+ res += " ";
+ res += obj.authors.map(key => key in info.authors ? info.authors[key] : key).join(", ");
+ res += ": &ldquo;" + obj.title + "&rdquo;.";
+ if ("preprint" in obj) {
+ res += " Preprint";
+ if (typeof obj.preprint == "string") res += ", " + obj.preprint;
+ res += ".";
+ }
+ if ("note" in obj) res += " " + obj.note;
+ if ("links" in obj && obj.links.length > 0) {
+ res += " [";
+ const anchors = [];
+ for (const link of obj.links) {
+ let name, url;
+ switch (link.type) {
+ case "arxiv":
+ name = "arxiv";
+ url = "https://arxiv.org/abs/" + link.id;
+ break
+
+ case "code":
+ name = "code";
+ url = link.url;
+ break;
+
+ case "pdf":
+ name = "PDF";
+ url = link.url;
+ break;
+
+ default:
+ throw new Error("Unknown publication link type " + link.type);
+ }
+ anchors.push("<a href=\"" + url + "\" target=\"_blank\">" + name + "</a>");
+ }
+ res += anchors.join(", ");
+ res += "]"
+ }
+ res += "</li>";
+ }
+
+ return res;
+}
+
+const publicationsHTML = buildPublicationsHTML(JSON.parse(fs.readFileSync(cmn.serverdir + "/publications.json")));
+
+
function anyComponentHidden(fname) {
return fname[0] == "." || fname.indexOf("/.") != -1;
}
@@ -153,7 +215,11 @@ function makeUrlSafe(req, sliceLength) {
app.get("/", function (req, res) {
- res.sendFile(cmn.serverdir + "/index.html");
+ // res.sendFile(cmn.serverdir + "/index.html");
+ res.send(
+ String(fs.readFileSync(cmn.serverdir + "/index.html"))
+ .replace(/<!--PUBS-REPLACE-START-->.*<!--PUBS-REPLACE-END-->/, publicationsHTML)
+ );
// res.send(
// String(fs.readFileSync(cmn.serverdir + "/index.html"))
// .replace(/<!--<<PULSE-KEYS>>-->/, whatpulse["keys"])
@@ -244,3 +310,5 @@ const server = httpServer.listen(PORT, function () {
const port = server.address().port;
console.log("Server listening at http://" + host + ":" + port);
});
+
+// vim: set sw=4 ts=4 noet: