This repository is an example of deploying a Docusaurus website to GitHub Pages using GitHub Actions.
It uses the new GitHub Pages experience with GitHub Actions to deploy the website.
Enable this experience in GitHub.com -> Repository -> Settings -> Pages -> Build and deployment -> Source by selecting GitHub Actions instead of the legacy Deploy from a branch option.
In GitHub.com -> Repository -> Settings -> Environments you should see a GitHub Environment named github-pages.
Generate a Docusuarus website using the following command:
yarn create docusaurus <folder-name> classic --typescriptMake the following changes to the docusaurus.config.js configuration file:
Create the constants
organizationNameandprojectNameconstorganizationName="<github-organization-name>";constprojectName="<repository-name>";
Set the URL
constconfig={// (...)url: `https://${organizationName}.github.io`,};constbaseUrl=/${projectName}/`;
Configure the base URL
constconfig={// (...)baseUrl: `/${projectName}/`,};
Set the
organizationNameandprojectNameoptionsconstorganizationName="<github-organization-name>";constprojectName="<repository-name>";constconfig={// (...) organizationName, projectName,};
Configure the blog and docs edit URLs
constconfig={// (...)presets: [["classic",/** @type {import('@docusaurus/preset-classic').Options} */({// (...)docs: {// (...)editUrl: `https://github.com/${organizationName}/${projectName}/tree/main/`,},blog: {// (...)editUrl: `https://github.com/${organizationName}/${projectName}/tree/main/`,},}),],],};
Use a GitHub Actions workflow template for GitHub Pages from the actions/starter-workflows repository. Place it in .github/workflows/<workflow-name>.yml.
Add steps for building the website before the GitHub Pages actions are executed and specify the path to the actions/upload-pages-artifact:
# (...)jobs:
deploy:
environment:
name: github-pagesurl: ${{ steps.deployment.outputs.page_url }}runs-on: ubuntu-lateststeps:
- name: Checkoutuses: actions/checkout@v3# 👇 Build steps
- name: Set up Node.jsuses: actions/setup-node@v3with:
node-version: 16.xcache: yarn
- name: Install dependenciesrun: yarn install --frozen-lockfile --non-interactive
- name: Buildrun: yarn build# 👆 Build steps
- name: Setup Pagesuses: actions/configure-pages@v3
- name: Upload artifactuses: actions/upload-pages-artifact@v2with:
# 👇 Specify build output pathpath: build
- name: Deploy to GitHub Pagesid: deploymentuses: actions/deploy-pages@v2