Deploy on Netlify

This article contains step-by-step instructions on how to deploy sites on Netlify.

There are multiple ways to deploy sites on Netlify, this article introduces the approach of using file-based configuration, which is more flexible than dashboard settings.

Deploy Sites via File-based Configuration

Create Netlify Configuration File

Firstly, create the following configuration file, and commit it to your repo.

netlify.toml
 1[build]
 2command = "npm ci && hugo --minify --gc -b $URL"
 3publish = "public"
 4
 5[build.environment]
 6NODE_VERSION = "19"
 7HUGO_VERSION = "0.121.2"
 8HUGO_ENABLEGITINFO = "true"
 9HUGO_ENV = "production"
10GO_VERSION = "1.20"
11
12[[headers]]
13  for = "/*"
14  [headers.values]
15    Referrer-Policy = "strict-origin-when-cross-origin"
16    X-Content-Type-Options = "nosniff"
17    X-Frame-Options = "deny"
18    X-XSS-Protection = "1; mode=block"
19
20# multilingual 404 pages, remove it on monolingual sites.
21[[redirects]]
22  from = "/en/*"
23  to = "/en/404.html"
24  status = 404
25
26[[redirects]]
27  from = "/zh-hans/*"
28  to = "/zh-hans/404.html"
29  status = 404
30
31# fallback 404 page.
32[[redirects]]
33  from = "/*"
34  to = "/404.html"
35  # to = "/en/404.html" # use this instead if defaultContentLanguageInSubdir is enabled.
36  status = 404

Create a Site

  1. Login to Netlify dashboard.
  2. Click the Add new site, and select the Import an existing project option.
  3. Select the repository.
  4. Leave the form as it is, since we’ve configured via netlify.toml.
  5. Deploy site.