What If... Hashnode in the Command Line?
Table of contents
Those who are reading this article would have a bunch of questions or a curiosity to see what this is about. Let's see if I can answer the questions and satisfy your curiosity. Let's roll!
Why
You may ask ...
Because why not!? I ditched VSCode and switched to Neovim 3 years ago. So, I've been living in the terminal for quite a while. Reading, Editing, Deleting, Moving, Copying files and directories in the command line, and much more (like grep
, awk
, sed
, curl
, etc.,) have made life easier. So why not just bring Hashnode right into the command line? That brings us to the next question.
What
what can it do
Okay, so what can it do? Currently, it supports features like
- Lookup your Profile
Explore Feed
- Switch Feed Categories
Read Posts
Like Posts
Open them in the browser
- Publish an article
- But before all that, setting auth token
what else
For those who think there are only limited features present, the following features are under work
- Write an article in the cli with a live preview
- Comments
Hmmm.... but how did I make it? Let's move to that question then.
How
If you have noticed from the gifs, I typed "golang" in the tags, so yea the cli is made with love, and Golang with awesome packages from Charm and spf13
Cobra - For managing commands and flags
Viper - For managing configs
Bubbletea - For Interactive CLI features
Bubbles - CLI Components
Lipgloss - Stying Bubble components
Using the cobra-cli
, I created and registered the necessary commands like
auth
- To set the Hashnode tokenme
- To look at profile infofeed
- To access feedpublish
- To publish an articlecreate
- To write an article
Then used viper
to create a config when auth cmd is used and also to get the token for other commands. Bonded necessary flags of cobra with viper.
Created fetchers for the profile, feed, posts, publish, like and saved them as functions that return the necessary info as a struct that can be used accordingly for the TUI.
Created Bubbletea models for feed, post, publish, and create, making them interactive with Init, Update, View methods.
Added styles to make the view look pretty and readable. Finally building the project to use as a CLI.
the cli is blazingly fast btw
Where
The project is on GitHub. You can access, contribute, and raise issues here. And that answers "where".
A Little Backstory
When I read about this hackathon, I read that it involves Hashnode APIs and we need to make a project with them. I didn't see the categories in the first place. Started creating this project and I was almost finished with the commands, that's when I reread the categories that had "integrations" and "starter kits". I thought to myself "this project doesn't fit in any of 'em. lol." but then I saw "APP IDEAS" listed in the categories and there was "An innovate alternative UI to publish a blog post to Hashnode" which fits as this is a "TUI" and you can publish posts with this cli!
And there you have this CLI. I'll create a new article that will explain the technical aspects in detail. If I missed any of your questions in this article feel free to leave a comment and I'll make sure to answer 'em! ok bye.