diff --git a/data/webmentions.json b/data/webmentions.json index d845a7c6..340f1d40 100644 --- a/data/webmentions.json +++ b/data/webmentions.json @@ -1,4 +1,18 @@ [ + { + "author": { + "name": "Wouter Groeneveld", + "picture": "/pictures/brainbaking.com" + }, + "name": "", + "content": "Hi Ana hope you’re doing well! The Webmention Guestbook idea is awesome! Looking forward to your future blog posts.", + "published": "2022-04-26T12:06:00+00:00", + "url": "https://brainbaking.com/notes/2022/04/26h12m06s10/", + "type": "mention", + "source": "https://brainbaking.com/notes/2022/04/26h12m06s10/", + "target": "https://brainbaking.com/", + "relativeTarget": "/" + }, { "author": { "name": "Chris Burnell", diff --git a/hooks/postdeploy.js b/hooks/postdeploy.js new file mode 100644 index 00000000..f0ac79ee --- /dev/null +++ b/hooks/postdeploy.js @@ -0,0 +1,20 @@ + +const { webmention } = require('jam-my-stack'); + +if(!process.env.WEBMENTION_TOKEN) { + throw "No webmention token set!" +} + +const wmconfig = { + endpoint: 'https://jam.brainbaking.com', + token: process.env.WEBMENTION_TOKEN +}; + +(async function() { + // 1. send webmentions + console.log("1. Sending webmentions...") + const since = await webmention.send("brainbaking.com", wmconfig) + console.log(` -- done`) + + console.log("-- all done!") +})() diff --git a/jamstack-init.js b/hooks/precommit.js similarity index 65% rename from jamstack-init.js rename to hooks/precommit.js index 0f4b5f69..e2c40cc1 100644 --- a/jamstack-init.js +++ b/hooks/precommit.js @@ -11,6 +11,8 @@ const wmconfig = { token: process.env.WEBMENTION_TOKEN }; +const rootdir = `${__dirname}/../`; + (async function() { // 1. parse Mastodon RSS feed // currently disabling notes, as after 3 months, I find these do not bring anything relevant to the table. @@ -28,30 +30,25 @@ const wmconfig = { // 2. update goodreads JS widget console.log("2. Updating Goodreads Widget...") const widget = await goodreads.createWidget("https://www.goodreads.com/review/grid_widget/5451893.Wouter's%20bookshelf:%20read?cover_size=medium&hide_link=&hide_title=&num_books=12&order=d&shelf=read&sort=date_added&widget_id=1496758344") - await fsp.writeFile(`${__dirname}/static/js/goodreads.js`, widget.replace(/src=/g, "loading=\"lazy\" src="), 'utf-8') + await fsp.writeFile(`${rootdir}/static/js/goodreads.js`, widget.replace(/src=/g, "loading=\"lazy\" src="), 'utf-8') // 3. build Lunr index console.log("3. Building lunr search index...") - const index = await lunr.buildIndex([`${__dirname}/content/post`]) - await fsp.writeFile(`${__dirname}/static/js/brainbaking-post.json`, JSON.stringify(index), 'utf-8') + const index = await lunr.buildIndex([`${rootdir}/content/post`]) + await fsp.writeFile(`${rootdir}/static/js/brainbaking-post.json`, JSON.stringify(index), 'utf-8') // 4. get webmentions console.log("4. Fetching webmentions...") const mentions = await webmention.getWebmentions("brainbaking.com", wmconfig) const json = JSON.stringify(mentions, null, 4) - await fsp.writeFile(`${__dirname}/data/webmentions.json`, json, 'utf-8') + await fsp.writeFile(`${rootdir}/data/webmentions.json`, json, 'utf-8') - // 5. send webmentions - console.log("5. Sending webmentions...") - const since = await webmention.send("brainbaking.com", wmconfig) - console.log(` -- done`) - - // 6. generate youtube thumbnails - console.log("6. Generating YouTube thumbnails...") + // 5. generate youtube thumbnails + console.log("5. Generating YouTube thumbnails...") await youtube.thumbify({ - postDir: `${__dirname}/content/post`, - downloadDir: `${__dirname}/static/img/yt`, - overlayImg: `${__dirname}/play.png` + postDir: `${rootdir}/content/post`, + downloadDir: `${rootdir}/static/img/yt`, + overlayImg: `${rootdir}/play.png` }) console.log("-- all done!") diff --git a/package.json b/package.json index 1bab6c67..1a4d00ff 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,8 @@ "lodash": ">=4.17.21" }, "scripts": { - "jamstack": "node jamstack-init.js" + "precommit": "node hooks/precommit.js", + "postdeploy": "node hooks/postdeploy.js" }, "repository": { "type": "git",