split jamstack-init into precommit and postdeploy to send webmentions AFTER deploying

This commit is contained in:
Wouter Groeneveld 2022-04-26 13:35:09 +02:00
parent 031d72a523
commit 4ad750a8d1
4 changed files with 47 additions and 15 deletions

View File

@ -1,4 +1,18 @@
[
{
"author": {
"name": "Wouter Groeneveld",
"picture": "/pictures/brainbaking.com"
},
"name": "",
"content": "Hi Ana hope youre 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",

20
hooks/postdeploy.js Normal file
View File

@ -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!")
})()

View File

@ -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!")

View File

@ -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",