aixlabDocs
GitHub Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

Hugo

Integrate github and hugo

To deploy your site to Pages:

  1. Log in to the Cloudflare dashboard and select your account.
  2. In Account Home, select Workers & Pages > Create application > Pages > Connect to Git.
  3. Select the new GitHub repository that you created and, in the Set up builds and deployments section, provide the following information:
    Configuration option Value
    Production branch main
    Build command hugo
    Build directory public
    Hugo allows you to configure the baseURL of your application. This allows you to utilize the absURL helper to construct full canonical URLs. In order to do this with Pages, you must provide the -b or --baseURL flags with the CF_PAGES_URL environment variable to your hugo build command.

Your final build command may look like this:

$ hugo -b $CF_PAGES_URL

After completing configuration, click the Save and Deploy button. You should see Cloudflare Pages installing hugo and your project dependencies, and building your site, before deploying it.

After deploying your site, you will receive a unique subdomain for your project on *.pages.dev. Every time you commit new code to your Hugo site, Cloudflare Pages will automatically rebuild your project and deploy it. You will also get access to preview deployments on new pull requests, so you can preview how changes look to your site before deploying them to production.

Based on cloudflare Docs from May 2023

Use a specific Hugo version

To use a specific version of Hugo, create the HUGO_VERSION environment variable in your Pages project > Settings > Environment variables. Set the value as the Hugo version you want to specify.

For example, HUGO_VERSION: 0.110.0.

If you plan to use preview deployments, make sure you also add environment variables to your Preview environment.

Set security headers

Create a file with the name _headers in the folder /static

/*
 Content-Security-Policy: default-src 'self';
 X-Frame-Options: SAMEORIGIN
 Permissions-Policy: autoplay=(*), fullscreen=(*), geolocation=* 
 X-XSS-Protection: 1; mode=block

# Implemented directly from cloudflare:
#  Strict-Transport-Security: max-age=31536000; includeSubDomains
# Implemented directly from cloudflare:
#  X-Content-Type-Options: nosniff
# Implemented directly from cloudflare:
#  Referrer-Policy: same-origin
# Unclear configuration
#  Permissions-Policy: autoplay=(*), fullscreen=(*), geolocation=*