Files
linkspin/tools/blog-publish.js
T

17 lines
1.1 KiB
JavaScript

// Runs INSIDE the LinkSpin container: node /tmp/blog-publish.js [draft]
// Seeds the posts in /tmp/blog-seed.json through blog.save() (same path Admin > Blog uses). Skips slugs that exist.
// Default status is published (Marty asked for the blog built out like InstantAdPay's); pass "draft" to seed drafts.
const fs = require('fs');
const blog = require('/app/blog.js');
blog.init({ dataDir: process.env.DATA_DIR || '/app/data' });
const status = process.argv[2] === 'draft' ? 'draft' : 'published';
(async () => {
const posts = JSON.parse(fs.readFileSync('/tmp/blog-seed.json', 'utf8'));
for (const p of posts) {
if (await blog.get(p.slug)) { console.log('exists ', p.slug); continue; }
const r = await blog.save(Object.assign({}, p, { status }), null);
console.log(r.error ? 'ERROR ' + p.slug + ': ' + r.error : (status + ' ' + r.post.slug + ' (' + r.post.body.split(/\s+/).length + ' words)'));
}
const all = await blog.listAll(); console.log('total posts:', all.length, '| published:', all.filter(x => x.status === 'published').length);
})().catch(e => { console.error('ERR', e.message); process.exit(1); });