Publish to GitHub Pages
Deploy your Bevel site to GitHub Pages with a complete GitHub Actions workflow, for project pages and user pages.
On this page
name: Pages
on:
push:
branches: [main]
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: pages
cancel-in-progress: false
jobs:
deploy:
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/setup-dotnet@0f4a354dd5547a28c70b7853dbd95d5b67886e73 # v6.1.0
with:
dotnet-version: 10.0.x
- name: Export the site
run: dotnet run -c Release -- --bevel-build dist
env:
BEVEL_PATH_BASE: /${{ github.event.repository.name }}
DOTNET_gcServer: 0
- uses: actions/configure-pages@45bfe0192ca1faeb007ade9deae92b16b8254a0d # v6.0.0
- uses: actions/upload-pages-artifact@fc324d3547104276b827a68afc52ff2a11cc49c9 # v5.0.0
with:
path: dist
- id: deployment
uses: actions/deploy-pages@368f82528645a54fb793d4d04e342629a3f51346 # v5.0.1
Commit this file, then turn on Pages (next step). Bevel's own docs deploy with a real, longer version of this workflow: .github/workflows/docs.yml.
Choose "GitHub Actions" as the Pages source
In your repository, open Settings → Pages. Under Build and deployment, set Source to GitHub Actions. Without this, the deploy job fails.
Read the path base from the environment
Your site lives at
https://you.github.io/repo/, so every link needs the/repoprefix. Set it from an environment variable so the same code works locally and in CI:samples/Bevel.Conference/Program.cscsharp // Hosted under a sub-path (GitHub Pages project sites)? Set it here and every link and asset follows. // Pass it from the environment so the same code works locally and in CI: BEVEL_PATH_BASE=/bevel-conf builder.AddBevel(options => { options.PathBase = Environment.GetEnvironmentVariable("BEVEL_PATH_BASE") ?? ""; // The origin of the published site. The calendar feed needs it for absolute session URLs. options.SiteUrl = Environment.GetEnvironmentVariable("BEVEL_SITE_URL") ?? "https://example.com"; });When the variable is not set, the path base stays empty and
dotnet watchserves at/.Push to main
The workflow exports into
distand uploads it. The deploy job publishes the artifact.
Project pages and user pages
| Site type | URL | Path base |
|---|---|---|
| Project pages | https://you.github.io/repo/ |
/repo |
User or organization pages (repository named you.github.io) |
https://you.github.io/ |
none |
| Project with a custom domain | https://docs.example.com/ |
none |
The workflow above uses the repository name, which is right for project pages. For a user page or a custom domain, leave the variable empty:
env:
BEVEL_PATH_BASE: ""
Add SiteUrl for sitemaps
Since 0.3 If you use MapSitemap, set SiteUrl to the origin. A path is ignored, so keep the sub-path in PathBase:
options.SiteUrl = "https://you.github.io";
options.PathBase = "/repo";
Handle 404s
GitHub Pages serves a root 404.html for unknown URLs. Map one:
app.MapStatic<NotFoundPage>("/404.html");
See a real workflow
This documentation site deploys with GitHub Pages. Read its workflow here: .github/workflows/docs.yml. It exports the docs under the /bevel path base. See Host under a sub-path for how the docs site sets its path base.