Use MWeb's Publish Script to publish to Hashnode

Crafting seamless user experiences with a passion for headless CMS, Vercel deployments, and Cloudflare optimization. I'm a Full Stack Developer with expertise in building modern web applications that are blazing fast, secure, and scalable. Let's connect and discuss how I can help you elevate your next project!
Get a Hashnode API key
To obtain a Hashnode API key, also known as a Developer Access Token, follow these steps:
Log In to Hashnode: Sign in to your Hashnode account using your credentials.
Access Account Settings:
Click on your profile picture located at the top-right corner of the page.
From the dropdown menu, select "Account Settings" to navigate to the settings page.
Navigate to Developer Settings:
- Once in the settings, click on the "DEVELOPER" tab. This section is specifically for managing developer-related configurations.
Generate the API Key:
In the Developer tab, look for an option to "Generate new token."
Click this button to create a new personal access token. This token will be displayed in the "Your tokens" section.
Secure Your API Key:
- Make sure to store this token securely, as it acts like a private key for accessing your Hashnode account via APIs[1][2][3].
By following these steps, you will have successfully generated a Hashnode API key that you can use for authenticating requests made through the Hashnode API.
To use MWeb's Publish Script to publish to Hashnode, you will need to integrate the Hashnode API into your script. Here’s a step-by-step guide on how you can achieve this:
Set Up MWeb and Prepare Your Post:
Ensure you have your markdown content ready in MWeb.
MWeb allows you to execute custom scripts for publishing, which can be configured in its preferences.
Configure the Publish Script:
Open MWeb and navigate to "Preferences" > "Extension" > "Publish Script".
Create a new script or modify an existing one to include the necessary commands for publishing to Hashnode.
Integrate Hashnode API:
Use the Hashnode API to publish your post. You will need to make a POST request to
https://api.hashnode.comusing thecreateStorymutation.Include your personal access token in the headers for authentication.
Sample Shell Script:
- Below is a sample shell script that demonstrates how you might configure the publish script in MWeb to post to Hashnode:
#!/bin/sh
# Set your Hashnode personal access token
PERSONAL_ACCESS_TOKEN="your_personal_access_token_here"
# Define the GraphQL mutation for creating a story
PUBLISH_MUTATION='mutation createStory($input: CreateStoryInput!) { createStory(input: $input) { code success message } }'
# Prepare the JSON payload with your post details
JSON_PAYLOAD=$(cat <<EOF
{
"query": "$PUBLISH_MUTATION",
"variables": {
"input": {
"title": "Your Post Title",
"contentMarkdown": "$(cat /path/to/your/markdown/file.md)",
"tags": [{"_id": "tag_id", "slug": "tag_slug", "name": "TagName"}]
}
}
}
EOF
)
# Make the API request to publish the post
curl -X POST https://api.hashnode.com \
-H 'Content-Type: application/json' \
-H "Authorization: $PERSONAL_ACCESS_TOKEN" \
--data-binary "$JSON_PAYLOAD"
Execute the Script:
- After configuring your script, right-click on your site category in MWeb, choose "Copy Publish Script command and Open Terminal...", and execute the script by pasting it into the terminal.
This setup allows you to automate posting from MWeb directly to Hashnode using their API[1][4][6]. Make sure you replace placeholders like your_personal_access_token_here, Your Post Title, /path/to/your/markdown/file.md, and tag details with actual values relevant to your content and Hashnode setup.
Citations: [1] https://hashnode.com/blog/publishing-a-blog-post-to-hashnode-using-a-custom-editing-interface [2] https://www.mweb.im/how_to_use_shell_script.html [3] https://support.hashnode.com/en/articles/8119381-how-to-publish-articles-from-github [4] https://www.codybontecou.com/programmatically-posting-to-your-favorite-blogs.html [5] https://support.hashnode.com/en/articles/6423225-markdown-guidelines [6] https://catalins.tech/hashnode-api-how-to-display-your-blog-articles-on-your-portfolio-page/






