This will take your private Obsidian vault repo, and publish it to GitHub pages using Quartz.
The current way that Quartz works is kind of odd. It requires you to have the full source code of Quartz in a git repository, then have your Vault within the content
directory of Quartz. Odd.
I’ve built a GitHub action that obfuscates much of the setup of Quartz so all you’ll need for your GitHub pages repository is the quartz.config.ts
file, along with the deploy.yml
GitHub action
There are actually a few things that are needed for this to work.
- Your Obsidian vault needs to notify the GitHub pages repo on push, which requires a Personal Access Token.
- GitHub actions will run a quartz build on the GitHub Pages repo, requiring it to pull your vault, which requires a Deploy Key.
- Quartz will then publish it’s output to GitHub Pages.
Choose your repo for hosting the GitHub pages content. I’m going to use my User github.io repository along with a CNAME file so my notes can be accessed via a custom URL.
Create a SSH Deploy Key
In your terminal, ssh-keygen -t ed25519 -C "[email protected]"
No password, find the Public and Private keys in ~/.ssh/
Vault Repo
Add the Public key (.pub) as a Deploy Key
Your GitHub pages repo
Add the Private key as an Action Secret. (I called it OBSIDIANDEPLOYKEY)
Create an Access Token
This is needed for permission to run the Dispatch. Create a fine-grained PAT. Give it Actions Read & Write permissions on the Quartz repository.
Vault repo
Add the token as an Action Secret.
GitHub Pages repo
Add in the deploy.yml
file.
.github/workflows/deploy.yml
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
name: Deploy Quartz site to Github Pages
# Run when there is a push to this repo, or a workflow dispatch from my vault repo
on:
push:
branches:
- master
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
# Check out this repo
- uses: actions/checkout@v4
# Setup node for this repo
- uses: actions/setup-node@v4
with:
node-version: lts
# Checkout Quartz, putting it in the `quartz` subdirectory
- uses: actions/checkout@v4
with:
repository: "jackyzha0/quartz"
ref: v4.2.3
path: quartz
# npm ci on Quartz
- name: Install Dependencies
working-directory: ./quartz
run: npm ci
# Copy my Quartz Config file
- name: Copy Quartz config
run: cp quartz.config.ts quartz/
# Checkout my Vault into quartz/content
# If it's a private repo, make sure to add the deploy key
- name: Checkout Obsidian repo
uses: actions/checkout@v4
with:
repository: ${{ secrets.VAULTREPO }}
path: quartz/content
ssh-key: ${{ secrets.NOTESPRIVATEKEY }}
# Build the Quartz public folder
- name: Build Quartz
working-directory: ./quartz
run: npx quartz build
# Upload the Quartz public folder as an artifact
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: quartz/public
publish:
permissions:
pages: write
id-token: write
needs: build
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
# Deploy the Quartz public folder artifact
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
You should also put your quartz.config.ts
file in the root of the repo
Vault repo
The only addition to the vault repo is the following file
.github/workflows/dispatch.yml
name: Trigger Github Pages rebuild
on:
push:
branches:
- master
jobs:
trigger:
runs-on: ubuntu-latest
steps:
- run: |
repo_owner="YOURGITHUBUSER"
repo_name="YOURPAGESREPO"
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.QUARTZDISPATCH }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/$repo_owner/$repo_name/actions/workflows/deploy.yml/dispatches \
-d '{"ref":"master"}'
Finally
Commit the Github Pages repo first. It should build the Vault repo and publish to Github Pages. After a successful build, then commit the Vault repo. At this point, any Pushes to the Vault repo will trigger a dispatch to the Pages repo and built it.