メインコンテンツへスキップ

HugoサイトをCloudflare Pagesにデプロイする

·466 文字·1 分
目次

HugoサイトをCloudflare Pagesにデプロイする
#

この記事では、Hugoで作成したサイトをCloudflare Pagesにデプロイする方法について解説します。

Cloudflare Pagesの設定
#

  1. Cloudflareアカウントにログインし、Pagesの画面を開きます。

  2. 「Create project」をクリックし、Hugoサイトのリポジトリを選択します。

  3. ビルド設定を行います。

    • Framework preset: Hugo
    • Build command: hugo
    • Build output directory: public
  4. 環境変数を設定します。

    • HUGO_VERSION: 0.118.2 (または、お使いのHugoのバージョン)
  5. 「Save and deploy」をクリックし、デプロイを開始します。

エラーが発生した場合
#

デプロイ中に以下のエラーが発生する場合があります。

ERROR render of "page" failed: "/opt/buildhome/repo/themes/ananke/layouts/_default/baseof.html:26:15": execute of template failed: template: _default/single.html:26:15: executing "_default/single.html" at <partials.Include>: error calling Include: "/opt/buildhome/repo/themes/ananke/layouts/partials/site-style.html:1:16": execute of template failed: template: partials/site-style.html:1:16: executing "partials/site-style.html" at <partials.IncludeCached>: error calling IncludeCached: "/opt/buildhome/repo/themes/ananke/layouts/partials/func/style/GetMainCSS.html:71:23": execute of template failed: template: partials/func/style/GetMainCSS.html:71:23: executing "partials/func/style/GetMainCSS.html" at <css>: can't evaluate field Sass in type interface {}

このエラーは、Hugoのバージョンとテーマの互換性がない場合に発生します。 Cloudflare Pagesの環境変数に HUGO_VERSION を設定することで、この問題を解決できます。

まとめ
#

Cloudflare Pagesを使用することで、Hugoサイトを簡単にデプロイできます。 ぜひお試しください。