mirror of
https://github.com/GenderDysphoria/GenderDysphoria.fyi.git
synced 2025-11-25 20:42:40 +00:00
Created the page-concatinator build module
This produces a single unified version of the entire GDB on one page at /gdb/printable
This commit is contained in:
60
build/page-concatinator.js
Normal file
60
build/page-concatinator.js
Normal file
@@ -0,0 +1,60 @@
|
||||
|
||||
const Page = require('./page');
|
||||
|
||||
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);
|
||||
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
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user