Sending WebSub notifications from static sites using Netlify functions

As part of my iterative intentions for 2018, I started a project to rebuild and simplify my website. I’ve used Jekyll for quite some time (either by itself or with Octopress), and as part of the latest iteration of the site, I’ve been working to align the site more with Indieweb principles, and to smooth the deployment path for my site by hosting it on Netlify.

One challenge with Jekyll and other static site generators is that “dynamic-ish” functionality, including sending notifications through protocols like WebSub. The trouble is knowing where these actions fit into the build process for your site: you don’t want to send the notifications before your site gets built, or pushed to the CDN hosting your site. Recently, Netlify announced a private beta for its new Netlify Functions service, which provides lambda-style functions deployed as part of your site deployment. One of the neat features that exists as of the beta is the ability to trigger the functions via Netlify events, like when your site successfully deploys.

As a beta service, some of the features are still somewhat rough around the edges (not to mention the documentation). Nonetheless I was able to get a proof of concept working pretty quickly, as I flew from California to DC for Code4lib2018. So, what does this look like in practice? I used netlify-lambda to help me build out the function locally. The code itself is fairly simple and is fired on a deploy-succeeded event: it checks to see if the deploy happened in production, attempts to ping my Superfeedr hub, and handles errors somewhat gracefully, with some light logging for debugging. I did a little refactoring based on Alex MacArthur’s post on building Netlify lambdas, which helped me think through some of the complexity on dealing with Netlify build environment variables. I couldn’t get that to work quite right, so I’m using sed to inject the variable’s value instead. Not pretty, but it works (for now).

This has been a great deal of fun to experiment with, and at some point, I’m hoping to experiment by adding the ability to send Webmention requests directly from this or a similar function as well. If you’re a Netlify user and would like to experiment during the Netlify Functions beta, you can request access.