This document outlines the steps involved in setting up a static website built with 11ty (Eleventy) and deployed using GitHub Pages and GitHub Actions. It aims to provide a clear and concise guide for developers who want to automate their deployment process and host their 11ty sites on GitHub Pages.
Before proceeding, ensure you have the following:
If you haven't already, set up your 11ty project with the following file structure:
prespedro-portfolio/ ├── src/ (11ty source files) │ └── index.njk ├── .eleventy.js (11ty configuration) ├── .gitignore ├── CNAME (custom domain file) ├── package-lock.json └── package.json
Configure your .eleventy.js file to use src as the input directory and _site as the output directory:
module.exports = function (eleventyConfig) {
return {
dir: {
input: "src",
output: "_site",
},
};
};
Create a .gitignore file to exclude node_modules and _site from version control:
node_modules _site
Create a CNAME file in the root directory with your custom domain (e.g., presidentpedro.com).
Install your project dependencies using npm install.
Establish a branching strategy with three key branches:
node_modules (excluded from version control).CNAME file.Automate your deployment process using GitHub Actions:
.github/workflows directory in the src branch.deploy.yml file in the workflows directory with the following content:
name: Deploy to GitHub Pages
on:
push:
branches:
- src
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Install dependencies
run: npm install
- name: Build 11ty site
run: npm run build
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: $
publish_dir: ./_site
publish_branch: build
cname: presidentpedro.com
Configure GitHub Pages to serve your site:
Ensure that GitHub Actions has the necessary permissions:
Deploy your site by following these steps:
src branch.src branch.build branch.build branch.Address common issues:
npm install on both the development and src branches.This workflow provides several benefits:
This document should serve as a valuable resource for you and anyone else who wants to set up GitHub Pages with GitHub Actions and 11ty. Feel free to add more details or customize it to fit your specific needs.
The following resources were helpful in developing this workflow:
GitHub Desktop can simplify Git operations:
If you don't have it already, download and install GitHub Desktop from desktop.github.com.
Open GitHub Desktop and add your repository.
Use GitHub Desktop to easily switch between branches, create new branches, view history, and manage merges.
Perform the following steps visually:
src and build branches.Combine VS Code and GitHub Desktop:
npx @11ty/eleventy --serve and npm run build.Here's the workflow using GitHub Desktop:
src branch: In GitHub Desktop, create a new branch named src.src folder and move `.gitignore`, `CNAME`, `package.json`, `package-lock.json`, and `.eleventy.js` back to the root..eleventy.js: Update the input directory to "src".build branch: In GitHub Desktop, create a build branch. Delete all files and copy the CNAME file into the build branch.src branch..github/workflows/deploy.yml: In VS Code, create the deploy.yml file.deploy.yml file to the src branch.By using GitHub Desktop, you can focus on code in VS Code while GitHub Desktop handles Git, streamlining your workflow.