Hosting blogs using Jekyll
This blog is a technical guide for setting up an automated sync between an Obsidian vault and a Jekyll blog site using GitHub Actions.
Introduction
I am maintaining my blogs inside an obsidian vault. I want my Jekyll website to pick up blogs from a particular directory in that vault periodically. I am syncing that vault to github.
Prerequisites
- Basic Jekyll Setup
- A repo which contains blog posts
Steps to sync blogs with jekyll
Step 1: Create a Personal Access Token (PAT)
Since the workflow needs to access and write to a private repository, we must create a Personal Access Token. This token will act as a password for our workflow.
- Go to GitHub Settings > Developer settings > Personal access tokens > Tokens (classic).
- Click Generate new token.
- Give the token a descriptive name, like “Jekyll-Obsidian-Sync.”
- Set an expiration date for the token.
- Under Select scopes, check the box for
repo. This gives the token read and write access to our private repositories. - Click Generate token and copy the token value immediately.
Step 2: Add the PAT to Obsidian Repository Secrets
We must store the token as a secret in our Obsidian repository to keep it secure.
- Navigate to the Obsidian repository on GitHub.
- Click Settings > Secrets and variables > Actions.
- Click New repository secret.
- In the “Name” field, type
JEKYLL_SYNC_TOKEN. - In the “Value” field, paste the token copied in the previous step.
- Click Add secret.
Step 3: Create the GitHub Actions Workflow File
Now we’ll create a YAML file that defines the sync workflow. This file lives in the .github/workflows/ directory of our Obsidian vault repository.
- In the local Obsidian vault repository, create a new directory named
.github/workflows. - Inside this new directory, create a file named
sync-to-jekyll.yml. - Paste the following code into the
sync-to-jekyll.ymlfile:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
name: Sync to Jekyll
on:
push:
branches:
- main # or whatever branch you use for your Obsidian notes
jobs:
sync:
runs-on: ubuntu-latest
steps:
- name: Checkout Obsidian Vault
uses: actions/checkout@v4
with:
repository: your-username/your-obsidian-vault # Replace with your repo name
token: $
- name: Configure Git
run: |
git config --global user.email "your-email@example.com"
git config --global user.name "your-username"
- name: Clone Jekyll Repository
run: |
git clone --single-branch --branch main https://your-username:$@github.com/your-username/your-jekyll-site.git
cd your-jekyll-site
- name: Copy Obsidian Notes to Jekyll Posts
run: |
mkdir -p your-jekyll-site/_posts
cp -r your-obsidian-vault/_posts/* your-jekyll-site/_posts/ # Assumes posts are in _posts folder in your vault
- name: Commit and Push Changes
run: |
cd your-jekyll-site
git add .
git commit -m "Automated sync from Obsidian vault"
git push
replace your-username, your-obsidian-vault, and your-jekyll-site with actual GitHub username and repository names.