Write once, publish everywhere: Integrate Github pages with Hashnode blogs

Write once, publish everywhere: Integrate Github pages with Hashnode blogs

  1. Techology šŸ› ļø
  2. in 1 hour
  3. 2 min read

I always wanted one place to write my blogs and publish them everywhere like on Hashnode or Medium (WIP). Itā€™s always time consuming to manually write and publish everywhere.

So, I thought why not automate it ?
Automate GIF

Since I am comfortable with Markdowns, and all I have to do is write in markdown its quite easier for me to maintain this single blog site.

Now all I have to do is figure out a way to publish in Hashnode. Hashnode is pretty cool šŸ˜Ž and I love the community there. It has the apiā€™s to publish blogs.

So hereā€™s the overall idea šŸ’”:

  1. Write blogs in markdown
  2. Detect file changes which were present only in posts folder.
  3. Publish the blog in Hashnode using Hashnode API.

btw this was the API I used to publish the blog in Hashnode : Hashnode API

Now step 1 and step 2 are pretty easy. I can use Github actions to detect file changes and publish the blog in Hashnode, but I didnā€™t wanted to use Github actions because it was again time consuming.

So I thought why not use astroā€™s post processing, where in after the project is built I can run a script to publish the blog in Hashnode.

But for this to happen I needed a way to detect changes and the only way was to compare it with previous change and check if the file was added or modified (assuming hashnode will take care of it since only title is required to for uniqueness I guess).

In git we can compare two commits and get the changes between them, for me I only wanted changeType (either M or A) and fileName which was present in posts folder.

git diff HEAD^ HEAD --name-status

Output :

M posts/AboutMe-shinmccold.md

Voila ! I got the changes and now I can publish the blog in Hashnode.
wow GIF

So I wrote a script to detect changes and publish the blog in Hashnode.

Note: Special thanks to my friend who is an expert in Git and Gerrit, who quickly gave the solution for this that even AI couldnā€™t give me. šŸ™Œ

Connect With Me

tech