hugo/content/en/hosting-and-deployment/hosting-on-github/index.md
Bjørn Erik Pedersen a6e635ca7d Squashed 'docs/' changes from 9b06f951e..fcc3ed651
fcc3ed651 Remove some expired new-in
a9c5981f5 Fix cascade example
82bb250fa Add some lines about permalinks tokens in front matter
328fe564e Remove some outdated new-in
fb140b153 Hide showcase menu entry
42d9d1c79 Update image formats from which EXIF data can be extracted
09ad56b6e netlify: Hugo 0.130.0
1d503f846 Merge branch 'tempv0.130.0'
e2458074d math: Add trigonometric functions and some angle helper functions
392afc8f9 Disable the showcase section for now
0300750f2 Improve example of image render hook
60a9306af Improve description of the .Site.RegularPages method
8d759175d Fix typos
55daa4554 Update XxHash.md
397c81cb7 Add namespace for hash functions
70fe8d2f0 netlify: Bump Hugo 0.129.0
5a9771aff Merge branch 'tempv0.129.0'
f9146575b Fix typo
e6e1fea49 Fix typo in Hugo docs | functions | partial
732d10ec4 source: Expose GitInfo Body
34c97e639 netlify: Hugo 0.128.2
3270587e9 Fix typo
727c5396e netlify: Hugo 0.128.1
80b6ae99c Update GitHub Pages workflow file example
027134102 Update GitHub Pages workflow file example
2600a8a2e Miscellaneous edits
3fdd5819b Update Build.md
7764005c3 Improve example of render hook directory structure
5e3941d82 Fix typos
748bf065f Restructure templates section
fafbf6566 Update Defer.md
012162e0d Document changes to template functions in v0.128.0
0990ce35b quick-reference: Update emojis
6677a30ef Update Goldmark configuration documentation
4449d530d Document new pagination config
0af8be439 Update Defer.md
56348196d netlify: Hugo 0.128.0
d67b6d82e Update content/en/functions/templates/Defer.md
23d996b3d Update content/en/functions/templates/Defer.md
7f7fb2f27 Document templates.Defer
5ada1e9d5 Fix docs merge (remove shortcode)
d27ee6156 Merge branch 'tempv0.128.0'
5d7317c84 Fix typo
7c18ee546 Update theme
83bfea63b Update theme
b274b3238 Merge commit '8b9803425e63e1b1801f8d5d676e96368d706722'
ff34a035a deploy: Add stripIndexHtml target option
d9e964bdb markup/goldmark: Add the Hugo Goldmark Extras "delete" extension
ac5bd16d2 deps: Upgrade github.com/alecthomas/chroma v2.13.0 => v2.14.0
25377171b config: Remove extraneous BuildConfig setting
0d2044f6d docs: Regen docshelper
a2548dac9 markup/goldmark: Support extras extension
9d0c86ee8 commands: Add gen chromastyles --lineNumbersTableStyle flag

git-subtree-dir: docs
git-subtree-split: fcc3ed651a1b6431303c2f88f20fa38531c52b3d
2024-08-09 15:17:43 +02:00

5.7 KiB
Raw Blame History

title description categories keywords menu toc aliases
Host on GitHub Pages Host your site on GitHub Pages with continuous deployment using project, user, or organization pages.
hosting and deployment
hosting
docs
parent
hosting-and-deployment
true
/tutorials/github-pages-blog/

Prerequisites

  1. Create a GitHub account
  2. Install Git
  3. Create a Hugo site and test it locally with hugo server.

Types of sites

There are three types of GitHub Pages sites: project, user, and organization. Project sites are connected to a specific project hosted on GitHub. User and organization sites are connected to a specific account on GitHub.com.

{{% note %}} See the GitHub Pages documentation to understand the requirements for repository ownership and naming.

{{% /note %}}

Procedure

Step 1
Create a GitHub repository.
Step 2
Push your local repository to GitHub.
Step 3
Visit your GitHub repository. From the main menu choose Settings > Pages. In the center of your screen you will see this:

screen capture {style="max-width: 280px"}

Step 4
Change the Source to GitHub Actions. The change is immediate; you do not have to press a Save button.

screen capture {style="max-width: 280px"}

Step 5
Create an empty file in your local repository.
.github/workflows/hugo.yaml
Step 6
Copy and paste the YAML below into the file you created. Change the branch name and Hugo version as needed.

{{< code file=.github/workflows/hugo.yaml copy=true >}}

Sample workflow for building and deploying a Hugo site to GitHub Pages

name: Deploy Hugo site to Pages

on:

Runs on pushes targeting the default branch

push: branches: - main

Allows you to run this workflow manually from the Actions tab

workflow_dispatch:

Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages

permissions: contents: read pages: write id-token: write

Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.

However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.

concurrency: group: "pages" cancel-in-progress: false

Default to bash

defaults: run: shell: bash

jobs:

Build job

build: runs-on: ubuntu-latest env: HUGO_VERSION: 0.128.0 steps: - name: Install Hugo CLI run: | wget -O ${{ runner.temp }}/hugo.deb https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb
&& sudo dpkg -i ${{ runner.temp }}/hugo.deb - name: Install Dart Sass run: sudo snap install dart-sass - name: Checkout uses: actions/checkout@v4 with: submodules: recursive fetch-depth: 0 - name: Setup Pages id: pages uses: actions/configure-pages@v5 - name: Install Node.js dependencies run: " -f package-lock.json && npm ci || true" - name: Build with Hugo env: HUGO_CACHEDIR: ${{ runner.temp }}/hugo_cache HUGO_ENVIRONMENT: production TZ: America/Los_Angeles run: | hugo
--gc
--minify
--baseURL "${{ steps.pages.outputs.base_url }}/" - name: Upload artifact uses: actions/upload-pages-artifact@v3 with: path: ./public

Deployment job

deploy: environment: name: github-pages url: ${{ steps.deployment.outputs.page_url }} runs-on: ubuntu-latest needs: build steps: - name: Deploy to GitHub Pages id: deployment uses: actions/deploy-pages@v4 {{< /code >}}

Step 7
Commit the change to your local repository with a commit message of something like "Add workflow", and push to GitHub.
Step 8
From GitHub's main menu, choose Actions. You will see something like this:

screen capture {style="max-width: 350px"}

Step 9
When GitHub has finished building and deploying your site, the color of the status indicator will change to green.

screen capture {style="max-width: 350px"}

Step 10
Click on the commit message as shown above. You will see this:

screen capture {style="max-width: 611px"}

Under the deploy step, you will see a link to your live site.

In the future, whenever you push a change from your local repository, GitHub will rebuild your site and deploy the changes.

Customize the workflow

The example workflow above includes this step, which typically takes 1015 seconds:

- name: Install Dart Sass
  run: sudo snap install dart-sass

You may remove this step if your site, themes, and modules do not transpile Sass to CSS using the Dart Sass transpiler.

Additional resources