This GitHub Action publishes blog posts from a GitHub repository to a specific publication on Hashnode. It reads markdown files, processes the frontmatter and content, and uses the Hashnode API to create, update, or delete posts.
- Create new posts on Hashnode if they do not exist.
- Update existing posts on Hashnode if they exist.
- Delists posts on Hashnode if the corresponding markdown file is not present in the current commit.
- Handles correct linking of cover images and inline images in the markdown content.
access-token
(required): Your Hashnode API Personal Access Token. See: Hashnode Developer Settingsadded-files
(required): The list of added files in the repository, automatically provided by thetj-actions/changed-files
action in the examples below.changed-files
(required): The list of changed files in the repository, automatically provided by thetj-actions/changed-files
action in the examples below.publication-host
(required): The publication host (e.g.,blog.mydomain.com
).posts-directory
(optional): The local directory in this repo containing the blog posts, if different from the root directory. Default:.
. Example:content/posts
.
result_json
: Publishes result as a JSON string.result_summary
: Publishes result summary formatted as text.
Create a new workflow file in your repository to define the steps required to publish the posts.
name: Publish My Hashnode Blog Posts
on:
push:
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v44
- uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Publish to Hashnode
uses: actions/publish-github-to-hashnode@v1
with:
added-files: ${{ steps.changed-files.outputs.added_files }} # Uses output from changed-files action
changed-files: ${{ steps.changed-files.outputs.all_changed_files }} # Uses output from changed-files action
access-token: ${{ secrets.HASHNODE_ACCESS_TOKEN }}
publication-host: 'blog.mydomain.com' # Your publication host
posts-directory: 'content/posts' # Dir within your repo containing the markdown files, if different from root dir
- Obtain your Hashnode API Personal Access Token. See: Hashnode Developer Settings
- Go to your repository on GitHub.
- Click on
Settings
. - Scroll down to
Secrets and variables
and click onActions
. - Click
New repository secret
. - Add a new secret with the name
HASHNODE_ACCESS_TOKEN
and your Hashnode API token as the value.
Ensure your repository contains the markdown files you wish to publish in the specified directory (default is the root of the repository).
Full list of frontmatter fields that can be used in the markdown files:
title
(required): Title of the post.subtitle
(optional): Subtitle of the post.slug
(required): Slug of the post.tags
(optional): Tags of the post (comma-separated).enableTableOfContents
(optional, default: false): Enable table of contents.publish
(optional, default: true): Should the post be published at this time.coverImage
(optional): Cover image relative path within the repository starting fromposts-directory
(as specified in pubish.yml) if provided.coverImageAttribution
: Information about the cover image attribution (optional)publishedAt
: Date and time when the post was published (optional)disableComments
(optional, default: false): Disable comments on the post.
---
title: Creating Spaghetti in Docker Compose
slug: creating-spaghetti-in-docker-compose
tags: docker,docker-compose
enableTableOfContents: true
coverImage: images/cover.jpg
---
## Introduction
This is an introduction to creating spaghetti in Docker Compose.
## Ingredients
- Docker Engine
- Spaghetti
- Sauce
- Cheese
- Love
## Steps
1. ...
2. ...
3. ...
The action will automatically convert relative image URLs to absolute URLs that point to the raw content on GitHub. Ensure your image paths in the markdown are correct relative paths.
You can utilize the result_json
output in subsequent steps to get the result of the publish operation in json format. The approach below can also be used with result_summary
for a text summary.
name: Publish My Hashnode Blog Posts
on:
push:
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v44
- uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Publish to Hashnode
id: publish
uses: actions/publish-github-to-hashnode@v1
with:
added-files: ${{ steps.changed-files.outputs.added_files }}
changed-files: ${{ steps.changed-files.outputs.all_changed_files }}
access-token: ${{ secrets.HASHNODE_ACCESS_TOKEN }}
publication-host: 'blog.mydomain.com'
posts-directory: 'content/posts'
- name: Get the output JSON
run: echo "${{ steps.publish.outputs.result_json }}"
To contribute to the development of this action, clone the repository, make your changes, and submit a pull request. Please ensure you submit a detailed Issue describing the work you are planning to do prior to submitting a PR.
This project is licensed under the MIT License.
If you have any questions or need support, please open an issue in the GitHub repository. I will do my best to help.