DEV Community


Self-updating blog with Jekyll and Github Action

mingyong profile image Ming Yong ・2 min read

I like blogging on platforms like Medium and DEV. Not only because of the audience it brings but, more importantly, the editor UI is way better than any UI I tried implementing for my Jekyll blog.

"So, I don't want to blog on my blog, but I want my blog to have all my work..." After some naps and showers, I settled with the idea of syncing articles from Medium and DEV to my Jekyll blog.

Step 1 of starting a project = see if someone has already done it.

Google points me to "Import DEV Posts To Jekyll With GitHub Actions" by Ben Greenberg. Thanks to Ben's well-documented code, I was comfortable enough to jump right onto modifying the index.js file after a basic Hellow World JS action tutorial by GitHub.

DEV action code

I used octokit/rest.js documentation as a reference of methods I can use. Maybe I should have just used that? Anyways, replace octokit with tools.github if you are using action-toolkit.

Code logic:

  • Create a branch
  • Grab all my Jekyll posts
  • Fetch DEV posts
  • Calculate the difference of both (posts from DEV - posts in Jekyll dev folder = N)
  • Exit if nothing new to add (N=0) OR create markdown files and update file content N times
  • When done, create a PR

Medium action code

Medium is a bit tricky. I tried a "convert RSS to Markdown" package, but that didn't work out. I ended up having just the summary on my blog with a link to the actual post.

Code logic:

  • Create a branch
  • Grab Jekyll posts
  • Fetch Medium posts with a "parse RSS to JSON" package
  • Loop through the retrieved array to create a markdown file and update file content for each. I know I will not post on Medium that often, so I compare the dates.
  • When done, create a PR

I added both actions to my blog repository on a monthly CRON schedule.

And that's my solution!

Although my code for these is not the prettiest, I can now blog freely on both platforms, merge my monthly updates and delete the branch without any worries.

Here's the link to my blog, DEV action, Medium action if you are interested. Please note that I didn't do a full test on them as I am not planning to publish them.

Discussion (0)

Editor guide