GenderDysphoria.fyi/build/page-concatinator.js

63 lines
1.5 KiB
JavaScript
Raw Normal View History

const Page = require('./page');
2021-03-25 14:05:29 -07:00
const { resolveDir } = require('./resolve');
function isDate (input) { return input instanceof Date; }
function min (...collection) {
if (isDate(collection[0])) return new Date(Math.min(...collection));
return Math.min(...collection);
}
function max (...collection) {
if (isDate(collection[0])) return new Date(Math.max(...collection));
return Math.max(...collection);
}
module.exports = exports = function (pages, target, paths, meta) {
const sources = {};
for (const page of pages) {
if (paths.includes(page.input)) sources[page.input] = page;
}
const result = new CombinedPage(target);
2021-03-25 14:05:29 -07:00
result.cwd = resolveDir(target);
result.source = '';
result.meta = {};
result.dateCreated = new Date();
result.dateModified = new Date(1990, 12, 1);
result.tweets = {};
result.images = {};
result.meta = meta;
result.classes = Array.from(new Set(meta.classes || []));
result.flags = result.classes.reduce((res, item) => {
var camelCased = item.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
res[camelCased] = true;
return res;
}, {});
for (const path of paths) {
const p = sources[path];
result.source += p.source;
result.dateCreated = min(result.dateCreated, p.dateCreated);
result.dateModified = max(result.dateModified, p.dateModified);
Object.assign(result.images, p.images);
Object.assign(result.tweets, p.tweets);
}
result.meta.date = result.dateCreated;
return result;
};
class CombinedPage extends Page {
async load () {
// do nothing
}
}