DEV Community

Matthew Claffey
Matthew Claffey

Posted on • Originally published at Medium on

Keeping your medium content fresh in your 11ty website using Github Actions and Netlify

On my personal website I use Medium as my content platform so I can channel my content via multiple channels. This is great because it allows me to take advantage of medium’s rich text editor and the implementation is really easy to do in 11ty.

Tech Stack

Website

The website is built by a popular framework called 11ty which is just a simple static site generator that helps you build Jamstack websites. It gets the medium data at the build time so it can build the blog pages before deploying them to Netlify.

Problem

The problem with this approach is that my content has a dependency on Medium to trigger a webhook that will trigger my Netlify build but it doesn’t have anything like that unless you upgrade your account.

Solution

The requirement I gave myself was to have the ability to keep my content fresh on the site. I post blog posts every couple of weeks so for me having a build at the end of the day is more than enough for what I wanted it to do.

I needed to figure out a way to trigger a Netlify build everyday just to keep the blog content fresh on my website. Netlify has a feature called build hooks which allows you to hit a Netlify endpoint that will then trigger a Netlify build.

You can access the build hooks in by going to Netlify —  Settings > Build & deploy > Continuous deployment > Build hooks.

Credit to Netlify website — https://docs.netlify.com/configure-builds/build-hooks/

Once the build hook is setup the next thing to do is to setup a Github action to hit this build hook endpoint every day or so. For example:

.github/workflows/main.yml

name: "Netlify Trigger - Get updates from Medium"

on:

schedule:

- cron: '0 0 \* \* \*'

jobs:

curl:

runs-on: ubuntu-latest

steps:

- name: curl

uses: wei/curl@v1

with:

args: -X POST -d {} https://api.netlify.com/build\_hooks/${{ secrets.NETLIFY\_BUILD\_HOOK }}
Enter fullscreen mode Exit fullscreen mode

This takes around 20s…

Note — make sure the build hook id is stored in your Github secrets so no one can spam your Netlify builds.

Conclusion

The nicer approach to this would have been having a webhook that listens to an event from Medium to see when a new blog post has been added but to get you up and running a cron job daily seem to do the trick.

Resources

Top comments (1)

Collapse
 
winstonpuckett profile image
Winston Puckett

It's so funny, I am looking for a way to do this with DEV. This is the first legitimate resource I've found for an 11ty project grabbing data. Thank you :)