jefklakscodex/hooks/precommit.js

40 lines
1.0 KiB
JavaScript

const { howlongtobeat, webmention, youtube } = require('jam-my-stack');
const fsp = require('fs').promises;
if(!process.env.WEBMENTION_TOKEN) {
throw "No webmention token set!"
}
const wmconfig = {
endpoint: 'https://jam.brainbaking.com',
token: process.env.WEBMENTION_TOKEN
};
const rootdir = `${__dirname}/../`;
(async function() {
// 1. get how long to beat times
console.log("1. adding Howlongtobeat info...")
await howlongtobeat.howlong({
postDir: `${rootdir}/content`,
downloadDir: `${rootdir}/static/img/hltb`
})
// 2. get webmentions
console.log("2. Fetching webmentions...")
const mentions = await webmention.getWebmentions("jefklakscodex.com", wmconfig)
const json = JSON.stringify(mentions, null, 4)
await fsp.writeFile(`${rootdir}/data/webmentions.json`, json, 'utf-8')
// 3. generate youtube thumbnails.
console.log("4. Generating YouTube thumbnails...")
await youtube.thumbify({
postDir: `${rootdir}/content`,
downloadDir: `${rootdir}/static/img/yt`,
overlayImg: `${rootdir}/play.png`
})
console.log("-- all done!")
})()