← back to Paul Conrad Cartoons Rebrand

scripts/build-artifact.js

17 lines

// Regenerate the shareable single-file Artifact from data/cartoons.json.
// Strips image fields (the Artifact is publicly shareable, so it hosts NO
// copyrighted cartoon images — metadata + link-out only) and injects the
// dataset into scripts/artifact-template.html. Output: artifact/index.html.
const fs = require('fs');
const path = require('path');
const root = path.join(__dirname, '..');
const data = JSON.parse(fs.readFileSync(path.join(root, 'data/cartoons.json'), 'utf8'));
const slim = {
  bio: data.bio,
  records: data.records.map(({ image, image_url, image_source, ...keep }) => keep)
};
const tpl = fs.readFileSync(path.join(__dirname, 'artifact-template.html'), 'utf8');
const out = tpl.replace('/*__DATA__*/{}', JSON.stringify(slim));
fs.writeFileSync(path.join(root, 'artifact/index.html'), out);
console.log('Wrote artifact/index.html —', (out.length/1024).toFixed(1) + 'KB,', slim.records.length, 'records');