Skip to content

Instantly share code, notes, and snippets.

@rmtsrc
Last active July 16, 2020 14:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rmtsrc/b5af88665efebf6ba6f1537dc3eb9425 to your computer and use it in GitHub Desktop.
Save rmtsrc/b5af88665efebf6ba6f1537dc3eb9425 to your computer and use it in GitHub Desktop.
Quickly and easily deploy an Eleventy Static Site to GitHub Pages with a custom domain

Deploying an Eleventy Static Site to GitHub Pages with a custom domain

Quickly and easily deploy an Eleventy Static Site to GitHub Pages with an optional custom domain.

Setup

  1. Use or create a new Eleventy project and commit and push it to a GitHub repo.
  2. In the root folder of your Eleventy project create a new file deploy.sh and copy the contents into it and on the commandline run chmod +x deploy.sh
  3. Edit your package.json file adding "deploy": "./deploy.sh" into the bottom of the scripts: section.

(Optional) Custom domain

  1. Create a new file .gh-pages in the root of your project containing your custom domain (without https://): e.g. your-blog.example.com
  2. Go to your domain providers settings and add a new DNS entry for your custom domain:
    • Type: CNAME
    • Name: your-blog.example.com
    • Target: your-github-username.github.io

Deploying

Run npm run deploy and after a couple of minutes your Eleventy project should be live at either: https://your-github-username.github.io/your-blog or on your custom domain: https://your-blog.example.com.

Run the same command again to update.

set -e
npm run build
rm -Rf /tmp/_site
mkdir /tmp/_site
cp -R .git /tmp/_site/
pushd /tmp/_site/
set +e
git branch -D gh-pages &>/dev/null
set -e
git checkout --orphan gh-pages
git reset
popd
[ -f ".gh-pages" ] && cp .gh-pages /tmp/_site/CNAME
pushd _site
cp -R * /tmp/_site/
pushd /tmp/_site/
git add -A
git commit -m 'Deploy site'
git push --force --no-verify --set-upstream origin gh-pages
popd
popd
rm -Rf /tmp/_site
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment