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 ?
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 š”:
- Write blogs in markdown
- Detect file changes which were present only in
posts
folder. - Publish the blog in Hashnode using Hashnode API.
btw this was the API I used to publish the blog in Hashnode :
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.
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
- Github: @shinmccold
- Twitter: @shinmccold1
- Youtube: @shinmccold
- Email: shinmccold@yahoo.com