This article was originally published on my personal blog
If you own a blog like me, but also cross-post your articles on platforms like Dev, Hashnode, and Medium, it gets tedious to post your articles in different places.
So, I created a simple CLI to cross-post my articles on these platforms easily. You can find it onNPMand check the code onGitHub.
Installation
In your terminal:
npm i -g cross-post-blog
Usage
Set Configuration
For the simplicity of the CLI, and considering most of the APIs of each of the platforms do not allow or provide endpoints for user authentication, you will need to get your access tokens, API keys, or integration tokens from your own profile before using cross-post. This will just need to be done the first time or if you want to change the tokens.
The tokens are all stored on your local machine.
Here's a guide on how to do this for each of the platforms:
dev.to
After logging into your account on dev.to, click on your profile image and then click on Settings
Then, click on the Accounts tab in the sidebar
Scroll down to the "DEV Community API Keys" section. You need to generate a new key. Enter "Cross Post" in the description text box or any name you want then click "Generate API key"
Copy the generated API key, then in your terminal:
cross-post config dev
You'll be prompted to enter the API key. Paste the API key you copied earlier and hit enter. The API key will be saved.
Hashnode
After logging into your account on Hashnode, click on your profile image and then click on "Account Settings"
In the sidebar click on "Developer"
Click the "Generate" button and then copy the generated access token.
Run the following in your terminal:
cross-post config hashnode
First, you'll be prompted to enter your access token. Then, you need to enter your Hashnode username. The reason behind that is that when later posting on hashnode your publication id is required, so your username will be used here to retrieve the publication id. Once you do and everything goes well, the configuration will be saved successfully.
Medium
After logging into Medium, click on your profile image and then click on "Settings"
Then click on "Integration Tokens" in the sidebar
You have to enter the description of the token then click "Get integration token" and copy the generated token.
In your terminal run:
cross-post config medium
Then enter the integration token you copied. A request will also be sent to Medium to get your authorId as it will be used later to post your article on Medium. Once that is done successfully, your configuration will be saved.
Cross-Posting Your Articles
To cross-post your articles, you will use the following command:
cross-post run <url> [options]
Whereurl
is the URL of your article that you want to cross-post.options
can be:
-
-p, --platforms [platforms...]
The platform(s) you want to post the article on. By default, if this option is not included, it will be posted on all the platforms. An example of its usage:
cross-post run <url> -p dev hashnode
-
-t, --title [title]
The title by default will be taken from the URL you supplied, however, if you want to use a different title you can supply it in this option. -
-s, --selector [selector]
by default, thearticle
selector will be used to find your article in the URL you pass as an argument. However, if you need a different selector to be used to find the article, you can pass it here.
This command will find the HTML element in the URL page you pass as an argument and if found, it will extract the title (if no title is passed in the arguments) and cover the image.
It should be noted that on all platforms the article will be posted as a draft, however, due to the limitations of the Hashnode API, it will be posted as "hidden from Hashnode" but it will be public in your publication.
UPDATE: In the latest version of this library, you can now pass the option -pu, --public
to publish the article publicly.
Conclusion
If you find any bugs or have any ideas you would like to contribute, please do so on the issues tab in theGitHub Repository!
Top comments (22)
I'm curious regarding the Medium integration. Posting to dev.to is easy since they fully support MarkDown, while Medium is .. Medium. Have you managed to overcome the "cross platform text editor compatibility" challenge?
Medium allows you to choose the type of content through a parameter βcontentFormatβ and you can pass it markdown or html. Iβm passing it markdown and it works pretty well
Does it also work for code blocks? Because if it does then wow man
Yea it does. To be honest this part of work isnβt done by me as Iβm using a library to transform the html to markdown, so itβs the one thatβs doing this part correctly!
Super cool, then I gotta check it out :)
That's fantastic; I'll have to look into it . The world of shooting games, which is for individuals who enjoy this game genre, is one of the most remarkable games in the genre of shooters that cannot be complete without 1v1 lol unblocked games. 1v1 lol unblocked is an online shooting game that you may play with or against other players. Here, you can build strong foundations and battle like great warriors. Use the skills you've mastered to kill the adversary and win.
Very nice job! I think we were kind of in the same timing π. I am also releasing a solution for cross-post on Medium, Hashnode and DEV integrated with Github. Feel free to try it: gitpublisher.com
great project, thanks for sharing! β€ π¦ π!
One super tiny thing, your first image for dev.to points the red arrow at "sign out" not at "settings".
I hope I find some time this week to give it a go!
Oh thanks for pointing that out I thought it was obvious that it was pointing at the settings. Iβll make sureto fix that
I mean this image for clarity:
It is obviously pointing at sign out (did you mean it was obvious you meant settings, as I completely agree then and I did say a super minor point!). The problem with the written word!
Anyway once again thanks for sharing a great CLI!
Yes thatβs what I meant. Iβll make sure to fix that. If you use it Iβd also appreciate the feedback!
Will do!
Tools like this are great, nice stuff. Definitely why we enable APIs at DEV.
nice one, but can you please give me more detail as which is the base article.
like for the canonical URL.
it has to be one of the above three ?
is there any way to ingratiate it with custom blogs.
Iβm not sure if I correctly understand you, but the base article is your own blog. You pass it in the command cross-post run and then it is posted to these 3 platforms or whichever you choose from them.
thats nice.
really cool. i can initgrate it in my personal blog and everytime i publish to my blog it will automate the publishing on these three...
thats super cool
you are genius...
Thank you! Currently it will publish them as a draft but I will be adding an option to publish them publicly soon.
may i have a one on one conversation on you regarding a project of mine if you don't mind..
Woww This is indeed amazing, Gave it a try and it worked!!!
Keep up the amazing work π
Thank you! Iβm glad it helped you as well.
Very cool! I'll give this a try today!
Hey, I created a SaaS tool for this purpose
integrateme.co/crosspost
And here's my post about it
dev.to/uzairali10/tool-to-cross-po...