Originally published on https://www.ankitbabber.com
If you don't want to use Jekyll as your static site generator for GitHub Pages and you want to have a custom domain for your GitHub Pages. This post is for you!
0. Dependencies
- Find a package manager for your current system and become familiar with it. I will use
brewsince I'm onmacOS. -
brew install node git ghor something similar for your package manager. - Using
ghor the GitHub cli makes working with GitHub easier.
1. Fork Quartz
- You can either use
Quartzas aTemplateorForkit.-
Template: copy ofQuartzas is, which might make keeping up withQuartzupdates slightly difficult. Updates will probably need a copy and paste ofQuartzat the root. Managing changes this way is difficult. -
Fork: easier to sync changes from the source. Any changes or modifications you make toQuartzwill becomemergeconflicts when an update happens, which are easier to manage with the right tools. - I recommend a
Fork. After you click onFork, STOP.
-
2. Name your Quartz Fork to initialize your GitHub Pages
- Since you can have only one public
Forkof Quartz at a time, I used myForkto create my GitHub Pages. - Under the
reponame after you clickFork, I enteredababber.github.io. When you name your QuartzForkrepo, replaceababberwith your GitHubusername, which initializes your GitHub Pages. - According to GitHub, you only have one GitHub Page per username.
- Once the
Forkis created. There are a few more steps before you're live.
3. Setup Quartz locally
# clone with git
git clone https://github.com/username/username.github.io.git
# 0. if you get an error, then use the GitHub
# cli to login to GitHub on your command line
# with the following command: `gh auth login`
# 1. clone with the github cli:
# gh repo clone username/username.github.io
# change directory into repo root
cd username.github.io
# install quartz dependencies
npm i
# initialize quartz and create an index.md
npx quartz create
# select: Empty Quartz
# select: Treat links as relative paths
# cd into content/, which is where quartz will
# look to create static pages
cd content
# create a test markdown file
touch test.md
# return to the repo root
cd ..
# this will build a preview of your blog
npx quartz build --serve
# 0. Ensure your browser allows http traffic
# 1. Once the build is done, go to http://localhost:8080
# in your browser.
# 2. In the left hand Explorer column, you should
# see test or the file created earlier.
4. Setup Deploy in Repo
- In your favorite code editor, create a file called
deploy.yml.- I recommend vscode.
- In the hidden directory
/username.github.io/.github/workflows/, adddeploy.yml - The content of
deploy.ymlis below:
name: Deploy Quartz site to GitHub Pages
on:
push:
branches:
- v4
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: "pages"
cancel-in-progress: false
jobs:
build:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for git info
- uses: actions/setup-node@v4
with:
node-version: 22
- name: Install Dependencies
run: npm ci
- name: Build Quartz
run: npx quartz build
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: public
deploy:
needs: build
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
5. Configure GitHub for Quartz Deploy
- Go to your Quartz
Fork, which will be something like:https://github.com/username/username.github.io. - Click on the
Settingstab for therepo. - In the left hand column, click on
Pages. - Under
Build and deploymentin theSourcedrop down menu, selectGitHub Actions - We've already setup the workflow with
deploy.yml. - At the bottom, select
Enforce HTTPSif not selected.
6. Sync Content
- In
quartz.config.ts, change thebaseUrlproperty to your GitHub Pages root domain, which should be something likeusername.github.io.
# check if everything looks fine
npx quartz build --serve
# commit the changes and deploy your quartz site
npx quartz sync
# 0. it will take a few minutes for your page to
# go live at username.github.io
# 1. in your username.github.io Actions tab, you
# can check the status of your build and deploy,
# any errors will be listed here
7. Setup Custom Domain with cloudflare
- Go to cloudflare
- Create an account.
- Search for a domain name.
- Register it (prices will vary depending on the domain name).
- From your
Account Homego to the domain you just created. - Click on
DNSand ensure you're in theRecordssection. - Select
Add record:- Type:
CNAME - Name:
@ - Target:
username.github.io - Select
Save
- Type:
- Select
Add record:- Type:
CNAME - Name:
www - Target:
username.github.io - Select
Save
- Type:
- For all the records that were created, ensure the
Proxy statusis OFF, we will enable this later. - On the left hand column of your custom domain page, click on
SSL/TLS. - Ensure you are on the
Overviewsection ofSSL/TLS. - Click on
Configure. - By default cloudflare sets
Custom SSL/TLStoFlexible. Change this toFull.- We need to do this because
username.github.iois being served to cloudflare overHTTPSby GitHub. - If we don't do this then your GitHub page may become unreachable and report the following error:
ERR_TOO_MANY_REDIRECTS. This is caused by a conlict with theCustom SSL/TLSFlexiblesetting and the Github PagesEnfore HTTPSsetting which creates an unexpected feedback loop.
- We need to do this because
8. Set GitHub Pages Custom Domain
- Verify your custom domain with the following instructions.
- Go to
https://github.com/username/username.github.io. - Click on your repo
Settingstab. - In the left hand column, click on
Pages. - Under
Custom domain, enter yourcustomdomain.comroot. Don't include the protocol or a subdomain. - Click on
Save. - Wait on this page for GitHub to perform checks. If everything was setup correctly,
DNS check successfulwill appear.
9. Final Things to Configure
- Go to your repo on your local machine.
- In
quartz.config.tschange thebaseUrlproperty to yourcustomdomain.comroot. - Sync changes to GitHub with:
npx quartz sync. - Wait for the build and deploy to finish in your
username.github.iorepo. - Check if your
customdomain.comis live. - Troubleshooting can be done in your
username.github.iorepoActionsandSettings --> Pagestabs. - Once everything is live and working correctly, go back to your cloudflare account.
- Log in.
- Go to your
customdomain --> DNS --> Records - Set
Proxy statusto ON for the previously createdCNAMErecords.
Top comments (0)