In the world of content creation, each platform offers unique advantages. Publishing articles on various platforms helps us expand our audience. However, managing and synchronizing your articles across multiple platforms can become a tedious task.
To address this need, I've developed an application called "Article as Code," which boasts several key features:
- Collects articles from your blog and stores them on GitHub as a "source of truth".
- Synchronizes all articles located in the repository to all your desired platforms.
- Allows you to write new articles by committing directly to this repository.
Setup your own AAC
Step 1: Create A New Github Repo
Step 2: Create Github Action Secretes
Go to Repo > Setting > Secrets and Variables > Actions > New repository secrete
You will need to create the following secrets:
-
DEVTO_TOKEN
: Your Dev.to authentication token. -
DEVTO_USERNAME
: Your Dev.to username. -
HASHNODE_TOKEN
: Your Hashnode authentication token. -
HASHNODE_USERNAME
: Your Hashnode username.
Step 2: Schedule sync process
To automate the synchronization process, we'll set up a GitHub Action workflow. Create a new file named .github/workflows/cronjob.yml
in your repository with the following contents:
name: "Cronjob"
on:
schedule:
- cron: '15 */6 * * *'
push:
branches:
- 'main'
jobs:
sync:
permissions: write-all
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '1.21.0'
- name: Prepare
run: export PATH=$PATH:$(go env GOPATH)/bin
- name: Install
run: go install github.com/huantt/article-as-code@v1.0.3
- name: Collect
run: |
article-as-code collect \
--username=${{ secrets.DEVTO_USERNAME }} \
--article-folder=articles
- name: Sync to dev.to
run: |
article-as-code sync \
--username=${{ secrets.DEVTO_USERNAME }} \
--auth-token=${{ secrets.DEVTO_TOKEN }} \
--article-folder=articles \
--destination="dev.to"
- name: Sync to hashnode.dev
run: |
article-as-code sync \
--username=${{ secrets.DEVTO_USERNAME }} \
--auth-token=${{ secrets.HASHNODE_USERNAME }} \
--article-folder=articles \
--destination="hashnode.dev"
- name: Commit
run: |
git config user.name github-actions
git config user.email github-actions@github.com
git add .
if git diff --cached --exit-code; then
echo "No changes to commit."
exit 0
else
git commit -m "update"
git rebase main
git push origin main
fi
This GitHub Action will run every 6 hours or whenever you push a new commit to the main branch. Here's what it does:
Collect all your articles from dev.to then store into the
articles
folder.Sync articles to dev.to
(In this case, it's redundant, but it will cover the scenario when you write a new article by committing directly to this repository.)Sync articles to hashnode.dev
References
- See my complete repository here:
About
This is the "single source of truth" that stores all my articles.
It utilizes huantt/article-as-code to collect, store, and sync all my articles to various platforms, including dev.to and hashnode.dev.
GitHub Action
I have created a GitHub action in the
.github/workflows
directory that runs every 6 hours or whenever you commit to themain
branch.My Recent Articles
Avoid Misunderstanding ON DELETE NO ACTION
Relational databases often provide several options for handling actions when a referenced row in a...
06/10/2024
[Golang] Understanding Unbuffered and Buffered Channels
Table of contents Channel capacity Behavior Closed channel Receive-Only & Send-only...
14/09/2024
Snowflake Schema vs. Star Schema: Pros, Cons, and Use Cases
Star Schema Structure: Central Fact Table: Contains quantitative data for...
12/09/2024
[Postgres] Isolation levels
In PostgreSQL, isolation levels determine how transaction integrity is maintained when multiple...
12/09/2024
ACID in Postgres
ACID is a set of properties that ensure reliable transactions…
- Source code:
huantt / article-as-code
Article as Code: Collect articles into files and synchronize them with publications
About
AAC
a.k.a.Article as Code
helps you collect articles from data sources, such as dev.to, and then stores them as static files.It also helps you sync static files to create articles on your publications.
Install
go install github.com/huantt/article-as-code@latest
Add
GOPATH/bin
directory to your PATH environment variable, so you can run Go programs anywhere.export GOPATH=$HOME/go export PATH=$PATH:$(go env GOPATH)/bin
Usage
Collect articles
Usage: collect [flags] Flags: -f, --article-folder string Article folder (default "data/articles") -h, --help help for collect-articles --rps int Limit concurrent requests (default 5) -u, --username string Username
For example
article-as-code collect \ --username=jacktt \ --rps=5 \ --article-folder=static
Sync articles
Usage: sync [flags] Flags: -f, --article-folder string Article folder (default "data/articles") -a, --auth-token string Auth token -h, --help help for sync-articles --rps int Limit concurrent requests (default 5) -u, --username string Username
For…
I will appreciate it if you contribute to support other platforms.
Top comments (6)
great article, thanks so much. Got a question. I get this error in my actions
Restore cache failed: Dependencies file is not found in /home/runner/work/articles/articles. Supported file pattern: go.sum
Also, I created the articles subfolder as well so the articles are added to it but though the job runs and shows that error i mentioned, the folder still does not get filled up with the articles. Any idea why?
Could you share me your repo?
yes i definitely can. Here it is github.com/apotitech/articles.git
I found the problem. Please update the Commit action with the following content:
I also updated something in this file, please rebase before trying it.
thanks so much for your help. I have adjusted all that. Now I get an error in the hashnode.dev process. Here is the error i get
Run article-as-code sync \
article-as-code sync \
--username=*** \
--auth-token=*** \
--article-folder=articles \
--destination="hashnode.dev"
shell: /usr/bin/bash -e {0}
[debug]/usr/bin/bash -e /home/runner/work/_temp/e078871f-4e65-4b6e-b0fb-e533f11e19a0.sh
time=2023-10-05T17:24:33.645Z level=ERROR msg="[map[extensions:map[code:DATASOURCE_ERROR] locations:[map[column:3 line:2]] message:It seems you have provided incorrect data path:[createStory]]]"
Error: Process completed with exit code 1.
Any idea what may cause this ?
I also did some changes in the sync.yml file to try and fix but same error
github.com/apotitech/articles/comm...
Please update to the latest version from /huantt/articles. Then, please let me know if you still encounter any errors.