This is the (custom) workflow I use to automatically tweet after publishing new content to my blog.
When I publish new content to this blog, a tweet like this gets published.
Every time I get close to wrapping up a project working with a new designer, I’m reminded of the benefit of considering extremes early on. We require so much flexibility and variability today that it’s impossible to capture a single, idealistic design. https://t.co/qTphiBEbNf— Sean C Davis (@seancdavis29) July 22, 2022
I built the workflow to support this from scratch. Let's look at how it works.
For me, this isn't some elaborate and secret plan to get a million followers or massively boost my pageviews. I have a simple rule: When I publish something new, I share it at least once.
I built this workflow to solve a simple issue with timing and context switching.
Before this process was in place, I would draft an article, review/edit it, publish it, then share it. The time between each of those steps varied from post to post, but could be as long as days or weeks.
By the time the article is ready to be shared, I'm often done thinking deeply about it. I've already spent much time in the zone, and have moved onto something else. To author a meaningfully contextual message is to refocus my brain on the article, come up with something clever, grab the URL, and publish a tweet. Of course, I also have to wait for the production build to finish and then make sure I remember to actually send the tweet (which I've forgotten a number of times).
After putting this process in place, I can author the tweet while I'm writing the article. As you'll see, I don't even have to know what the URL is going to be. I just leave a short message for the tweet, and once the publishing process completes itself, the tweet is automatically published to Twitter.
No context switching. No reminder setting. I'm onto the next thing while my Twitter account stays active.
There are three components that make up the engine that drives this process:
This is how it works:
tweet frontmatter: My blog content is stored in markdown files, which use YAML frontmatter to store meta properties about the post. When I publish a new post, I add a property
tweet where the value is the body of the tweet to publish. Here's an example that you can see matches the tweet at the beginning of this article.
main branch, a new Netlify build gets kicked off. When a build on the main branch is successful, my netlify-plugin-github-dispatch plugin uses the GitHub API to release a dispatch, which triggers the GitHub workflow.
npm run publish-tweets from my website's working directory (
www in the monorepo).
tweet property in the frontmatter, verifies that it hasn't been sent yet, then publishes the tweet, appending the URL for the post to the bottom of the tweet text. It then cleans up by removing the
tweet property for the post (so that the script doesn't try to send the tweet again the next time it runs) and commits the change to the repo.
Big thanks to the official netlify-plugin-github-dispatch plugin! I borrowed heavily from this code, and slimmed it down to solve my specific problem.
I'm about three months into this workflow and it has been a total game-changer for me. My account is more consistently active on Twitter than ever before.
And even though I don't get much interaction on these tweets, they are helping, and every little bit helps to boost the visibility of each piece of content I'm putting out there, which makes it feel more worthwhile to me.
While you're welcome to take this code and make it work for you. If you do, let me know. I've been considering building a solution that could be more turnkey, but would need real use cases to work against.
Inlining critical CSS is a breeze for classic SSG sites built and deployed using Netlify. Here’s how it works.