';
var marked = require("marked");
var fs = require("fs-extra");
// bundle all content in a specific locale for use by the app
var locale = process.env.locale || "en-GB";
// shim nodejs so that it knows what to do with jsx files: return empty objects.
var Module = require('module');
var originalRequire = Module.prototype.require;
Module.prototype.require = function() {
try {
return originalRequire.apply(this, arguments);
} catch (e) {
return {};
}
};
/**
* Split data up into "markdown" and "latex"
*/
function chunk(data) {
var p = 0, e = 0, chunks = [];
while (p !== -1) {
let s = data.indexOf('\n\\[', p);
if (s === -1) {
chunks.push({
latex: false,
data: data.substring(p)
});
break;
}
chunks.push({
latex: false,
data: data.substring(p, s)
});
e = data.indexOf('\\]\n\n', s) + 4;
chunks.push({
latex: true,
data: data.substring(s, e)
});
p = e;
}
return chunks;
}
// Then get the section map. This will try to load .jsx code, which will fail,
// but the above shim makes a failure simply return an empty object instead.
// This is good: we only care about the keys, not the content.
var index = require("./components/sections");
var sections = Object.keys(index);
var content = {};
sections.forEach((cname, number) => {
var loc = `./components/sections/${cname}/content.${locale}.md`;
var data, title;
try {
data = fs.readFileSync(loc).toString();
// convert all non-latex data
data = data.split(glue).map(content => {
return chunk(content).map(chunk => {
if (chunk.latex) return chunk.data;
let d = marked(chunk.data)
// And then some post-processing...
d = d.replace(/
]+>([^<]+)<\/h1>/,function(_,t) {
title = t;
return ``;
});
d = d.replace('
', '')
// serious can we fucking not, please.
.replace(/'/g, "'")
.replace(/&/g, '&')
.replace(/"/g, '"')
return d;
}).join('');
}).join(glue);
} catch (e) {
data = '';
title = `Unknown title (${cname})`;
}
content[cname] = {
title: title,
getContent: "