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 = """
 3DART_SASS_VERSION="${DART_SASS_VERSION:-1.79.5}" && \
 4curl -LJO https://github.com/sass/dart-sass/releases/download/${DART_SASS_VERSION}/dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz && \
 5tar -xf dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz && rm dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz && \
 6export PATH=/opt/build/repo/dart-sass:$PATH && \
 7npm ci && \
 8hugo --minify -b $URL
 9"""
10publish = "public"
11
12[build.environment]
13NODE_VERSION = "19"
14HUGO_VERSION = "0.121.2"
15HUGO_ENABLEGITINFO = "true"
16HUGO_ENV = "production"
17GO_VERSION = "1.20"
18
19[[headers]]
20  for = "/*"
21  [headers.values]
22    Referrer-Policy = "strict-origin-when-cross-origin"
23    X-Content-Type-Options = "nosniff"
24    X-Frame-Options = "deny"
25    X-XSS-Protection = "1; mode=block"
26
27# multilingual 404 pages, remove it on monolingual sites.
28[[redirects]]
29  from = "/en/*"
30  to = "/en/404.html"
31  status = 404
32
33[[redirects]]
34  from = "/zh-hans/*"
35  to = "/zh-hans/404.html"
36  status = 404
37
38# fallback 404 page.
39[[redirects]]
40  from = "/*"
41  to = "/404.html"
42  # to = "/en/404.html" # use this instead if defaultContentLanguageInSubdir is enabled.
43  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.
razonyang
Saturday, December 21, 2024 Saturday, April 15, 2023