This page looks best with JavaScript enabled
⚠️

【Hugo】Hugo + Netlifyでデプロイ

 ·   ·  ☕ 3 分で読めます
✏️

Netlifyのデプロイ

Netlify側で設定する方法と、netlify.tomlに設定を記述する方法がある。

netlify.tomlで設定する場合は、Netlifyの設定はBuild commandとPublish directoryなども空白のままでいい。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
[build]
command = "hugo"  # Build commandに相当
publish = "public"  # Publish directoryに相当

[context.production.environment]
HUGO_ENABLEGITINFO = "true"
HUGO_ENV = "production"
HUGO_VERSION = "0.74.2"

[context.split1]
command = "hugo --enableGitInfo"

[context.split1.environment]
HUGO_ENV = "production"
HUGO_VERSION = "0.74.2"

[context.deploy-preview]
command = "hugo -b $DEPLOY_PRIME_URL"

[context.deploy-preview.environment]
HUGO_VERSION = "0.74.2"

[context.branch-deploy]
command = "hugo -b $DEPLOY_PRIME_URL"

[context.branch-deploy.environment]
HUGO_VERSION = "0.74.2"

[context.next.environment]
HUGO_ENABLEGITINFO = "true"

ログ

Deploy logが以下のようになると成功。

12:04:15 AM: Build ready to start
12:04:17 AM: build-image version: ca811f47d4c1cbd1812d1eb6ecb0c977e86d1a1d
12:04:17 AM: build-image tag: v3.3.20
12:04:17 AM: buildbot version: be8ecf2af866e16fa4301cc5c14de2ccbbb21cf4
12:04:17 AM: Fetching cached dependencies
12:04:17 AM: Failed to fetch cache, continuing with build
12:04:17 AM: Starting to prepare the repo for build
12:04:18 AM: No cached dependencies found. Cloning fresh repo
12:04:18 AM: git clone https://github.com/aiandrox/aiandrox
12:04:18 AM: Preparing Git Reference refs/heads/master
12:04:21 AM: Different publish path detected, going to use the one specified in the Netlify configuration file: 'public' versus '/public' in the Netlify UI
12:04:21 AM: Different build command detected, going to use the one specified in the Netlify configuration file: 'hugo' versus 'hugo_0.74' in the Netlify UI
12:04:21 AM: Starting build script
12:04:21 AM: Installing dependencies
12:04:21 AM: Python version set to 2.7
12:04:22 AM: v12.18.0 is already installed.
12:04:23 AM: Now using node v12.18.0 (npm v6.14.4)
12:04:23 AM: Started restoring cached build plugins
12:04:23 AM: Finished restoring cached build plugins
12:04:23 AM: Attempting ruby version 2.7.1, read from environment
12:04:24 AM: Using ruby version 2.7.1
12:04:24 AM: Using PHP version 5.6
12:04:25 AM: 5.2 is already installed.
12:04:25 AM: Using Swift version 5.2
12:04:25 AM: Installing Hugo 0.74.2
12:04:26 AM: Hugo Static Site Generator v0.74.2-48565DE6/extended linux/amd64 BuildDate: 2020-07-17T17:32:27Z
12:04:26 AM: Started restoring cached go cache
12:04:26 AM: Finished restoring cached go cache
12:04:26 AM: go version go1.14.4 linux/amd64
12:04:26 AM: go version go1.14.4 linux/amd64
12:04:26 AM: Installing missing commands
12:04:26 AM: Verify run directory
12:04:27 AM: ​
12:04:27 AM: ┌─────────────────────────────┐
12:04:27 AM: │        Netlify Build        │
12:04:27 AM: └─────────────────────────────┘
12:04:27 AM: ​
12:04:27 AM: ❯ Version
12:04:27 AM:   @netlify/build 3.0.1
12:04:27 AM: ​
12:04:27 AM: ❯ Flags
12:04:27 AM:   deployId: 5f1460ef88a8fb00073eabd6
12:04:27 AM:   mode: buildbot
12:04:27 AM: ​
12:04:27 AM: ❯ Current directory
12:04:27 AM:   /opt/build/repo
12:04:27 AM: ​
12:04:27 AM: ❯ Config file
12:04:27 AM:   /opt/build/repo/netlify.toml
12:04:27 AM: ​
12:04:27 AM: ❯ Context
12:04:27 AM:   production
12:04:27 AM: ​
12:04:27 AM: ┌────────────────────────────────────┐
12:04:27 AM: │ 1. build.command from netlify.toml │
12:04:27 AM: └────────────────────────────────────┘
12:04:27 AM: ​
12:04:27 AM: $ hugo
12:04:34 AM: Building sites …
12:04:34 AM:                    | JA  | EN  | KO
12:04:34 AM: -------------------+-----+-----+------
12:04:34 AM:   Pages            | 206 |  13 |  13
12:04:34 AM:   Paginator pages  |   4 |   0 |   0
12:04:34 AM:   Non-page files   |   3 |   0 |   0
12:04:34 AM:   Static files     | 138 | 138 | 138
12:04:34 AM:   Processed images |   0 |   0 |   0
12:04:34 AM:   Aliases          |  53 |   1 |   1
12:04:34 AM:   Sitemaps         |   2 |   1 |   1
12:04:34 AM:   Cleaned          |   0 |   0 |   0
12:04:34 AM: Total in 7162 ms
12:04:34 AM: ​
12:04:34 AM: (build.command completed in 7.2s)
12:04:34 AM: ​
12:04:34 AM: ┌─────────────────────────────┐
12:04:34 AM: │   Netlify Build Complete    │
12:04:34 AM: └─────────────────────────────┘
12:04:34 AM: ​
12:04:34 AM: (Netlify Build completed in 7.3s)
12:04:34 AM: Caching artifacts
12:04:34 AM: Started saving build plugins
12:04:34 AM: Finished saving build plugins
12:04:34 AM: Started saving pip cache
12:04:34 AM: Finished saving pip cache
12:04:34 AM: Started saving emacs cask dependencies
12:04:34 AM: Finished saving emacs cask dependencies
12:04:34 AM: Started saving maven dependencies
12:04:34 AM: Finished saving maven dependencies
12:04:34 AM: Started saving boot dependencies
12:04:35 AM: Finished saving boot dependencies
12:04:35 AM: Started saving go dependencies
12:04:35 AM: Finished saving go dependencies
12:04:37 AM: Build script success
12:04:37 AM: Starting to deploy site from 'public'
12:04:37 AM: Creating deploy tree
12:04:37 AM: Creating deploy upload records
12:04:38 AM: 228 new files to upload
12:04:38 AM: 0 new functions to upload
12:04:44 AM: Starting post processing
12:04:44 AM: Post processing - HTML
12:04:44 AM: Mixed content detected in: /index.html
12:04:44 AM: --> insecure link urls:
12:04:44 AM:   - http://example.org/ja/
12:04:44 AM: Mixed content detected in: /ko/index.html
12:04:44 AM: --> insecure link urls:
12:04:45 AM:   - http://example.org/ko/index.xml
12:04:45 AM:   - http://example.org/ko/
...(略)
12:05:19 AM: Mixed content detected in: /en/tags/index.html
12:05:19 AM: --> insecure link urls:
12:05:19 AM:   - http://example.org/en/tags/index.xml
12:05:19 AM:   - http://example.org/en/tags/
12:05:19 AM: Post processing - redirect rules
12:05:19 AM: Post processing - header rules
12:05:19 AM: Post processing done
12:05:20 AM: Site is live

build

example.orgにリダイレクトする

1
2
3
- baseURL = "http://example.org"
+ baseURL = "https://aiandrox.netlify.app"
...

ここでURLを設定しないとhttp://example.orgにリダイレクトしてしまう。

Share on

END
END
@aiandrox

 
目次