HUGO ja 非公式

  • ニュース
  • ドキュメント
  • テーマ
  • コミュニティ
  • GitHub
gohugoio Star づけ
  暫定公開中 2024/09/16 (94d7f576a 対応, 2024/09/15)
  • Hugo について
    • 本節
    • Introduction
    • Hugo の機能
    • Privacy
    • セキュリティ
    • ライセンス
  • インストール
    • 本節
    • macOS
    • Linux
    • Windows
    • BSD
  • はじめよう
    • 本節
    • クイックスタート
    • ディレクトリ構造
    • 基本操作
    • 設定
    • Configure markup
    • 用語集
    • 本書以外の学習リソース
  • クイックリファレンス
    • 本節
    • Emojis
    • Functions
    • Methods
    • Page collections
  • コンテント管理
    • 本節
    • コンテントの構成
    • ページバンドル
    • コンテントフォーマット
    • フロントマター
    • ビルドオプション
    • ページリソース
    • イメージ処理
    • ショートコード
    • 関連コンテント
    • Sections
    • Content types
    • アーキタイプ
    • 分類
    • Summaries
    • Links and cross references
    • URL 管理
    • メニュー
    • コメント
    • マルチ言語
    • Markdown attributes
    • シンタックスハイライト
    • Diagrams
    • Mathematics
    • Data sources
    • Content adapters
  • テンプレート
    • 本節
    • はじめに
    • Template types
    • Lookup order
    • 基本テンプレート
    • Home templates
    • Single templates
    • Section templates
    • Taxonomy templates
    • Term templates
    • 部分テンプレート
    • コンテントビューテンプレート
    • ショートコードテンプレート
    • サイトマップテンプレート
    • RSS テンプレート
    • 404 テンプレート
    • robots.txt templates
    • メニュー
    • ページネーション
    • Embedded templates
    • Custom output formats
  • 関数
    • 本節
    • cast
    • collections
    • compare
    • crypto
    • css
    • data
    • debug
    • diagrams
    • encoding
    • fmt
    • global
    • go template
    • hash
    • hugo
    • images
    • inflect
    • js
    • lang
    • math
    • openapi3
    • os
    • partials
    • path
    • reflect
    • resources
    • safe
    • strings
    • templates
    • time
    • transform
    • urls
  • メソッド
    • 本節
    • Duration
    • Menu
    • Menu entry
    • Page
    • Pager
    • Pages
    • Resource
    • Shortcode
    • Site
    • Taxonomy
    • Time
  • レンダーフック
    • 本節
    • Introduction
    • Blockquotes
    • Code blocks
    • Headings
    • Images
    • Links
    • Passthrough
    • Tables
  • Hugo モジュール
    • In this section
    • Configure Hugo modules
    • Use Hugo Modules
    • Theme components
  • Hugo パイプ
    • 本節
    • Introduction
    • Transpile Sass to CSS
    • PostCSS
    • PostProcess
    • JavaScript building
    • Babel
    • Asset minification
    • Concatenating assets
    • Fingerprinting and SRI hashing
    • Resource from string
    • Resource from template
  • CLI
  • トラブルシューティング
    • 本節
    • Logging
    • Inspection
    • Deprecation
    • Performance
    • FAQs
  • 開発ツール
    • 本節
    • Editor plugins
    • Front-ends
    • 検索
    • Migrations
    • Other projects
  • ホスティングと開発
    • 本節
    • Hugo Deploy
    • Deploy with Rclone
    • Deploy with Rsync
    • Host on 21YunBox
    • Host on AWS Amplify
    • Host on Azure Static Web Apps
    • Host on Cloudflare Pages
    • Host on Firebase
    • Host on GitHub Pages
    • Host on GitLab Pages
    • Host on KeyCDN
    • Host on Netlify
    • Host on Render
  • 貢献
    • 本節
    • Development
    • ドキュメント
    • Themes
  • メンテナンス
はじめよう

基本操作

Hugo のコマンドラインインターフェース (command line interface; CLI) の機能は充実していて、しかも操作が簡単です。たとえコマンドライン操作の経験が少ない方でも安心して利用できます。

インストールの確認

Hugo を インストール したら、以下を実行して確認します。

hugo version

以下のような出力が行われます。

hugo v0.123.0-3c8a4713908e48e6523f058ca126710397aa4ed5+extended linux/amd64 BuildDate=2024-02-19T16:32:38Z VendorInfo=gohugoio

利用可能なコマンドの表示

利用可能なコマンドやフラグを確認するには、以下を実行します。

hugo help

サブコマンドのヘルプを見るには --help フラグを使います。 たとえば以下のとおりです。

hugo server --help

サイトの構築

サイトを構築するには cd によりプロジェクトディレクトリに入って以下を実行します。

hugo

hugo コマンドがサイトを構築します。 公開するファイルは public ディレクトリに出力されます。 サイトの公開を別ディレクトリとする場合は --destination フラグを用いるか、サイト設定において publishDir を設定します。

Hugo はサイトの構築にあたって public ディレクトリをクリアしません。 既存のファイルは上書きされ、ファイル削除は行われません。 この動作は意図的なものであって、ビルドした後に public ディレクトリに何かファイルを追加する場合があるかもしれないため、それを不用意に削除しないようにしているものです。

作業での必要に応じて、ビルドを行う際には、毎回 public ディレクトリを手動で削除することをお勧めします。

Draft, future, and expired content

Hugo allows you to set draft, date, publishDate, and expiryDate in the front matter of your content. By default, Hugo will not publish content when:

  • The draft value is true
  • The date is in the future
  • The publishDate is in the future
  • The expiryDate is in the past
v0.123.0 の新機能

Hugo publishes descendants of draft, future, and expired node pages. To prevent publication of these descendants, use the cascade front matter field to cascade build options to the descendant pages.

You can override the default behavior when running hugo or hugo server with command line flags:

hugo --buildDrafts    # or -D
hugo --buildExpired   # or -E
hugo --buildFuture    # or -F

Although you can also set these values in your site configuration, it can lead to unwanted results unless all content authors are aware of, and understand, the settings.

As noted above, Hugo does not clear the public directory before building your site. Depending on the current evaluation of the four conditions above, after the build your public directory may contain extraneous files from a previous build.

A common practice is to manually clear the contents of the public directory before each build to remove draft, expired, and future content.

サイトの開発とテスト

レイアウト開発やコンテントの生成中にサイトを確認したい場合は、cd によりプロジェクトディレクトリに入って以下を実行します。

hugo server

hugo server コマンドは、メモリ内にサイトを構築します。 そして小さな HTTP サーバーを使ってページ表示を行います。 hugo server を実行すると、ローカル端末には URL が表示されます。

Web Server is available at http://localhost:1313/

While the server is running, it watches your project directory for changes to assets, configuration, content, data, layouts, translations, and static files. When it detects a change, the server rebuilds your site and refreshes your browser using LiveReload.

Most Hugo builds are so fast that you may not notice the change unless you are looking directly at your browser.

LiveReload

While the server is running, Hugo injects JavaScript into the generated HTML pages. The LiveReload script creates a connection from the browser to the server via web sockets. You do not need to install any software or browser plugins, nor is any configuration required.

Automatic redirection

When editing content, if you want your browser to automatically redirect to the page you last modified, run:

hugo server --navigateToChanged

サイトのデプロイ

As noted above, Hugo does not clear the public directory before building your site. Manually clear the contents of the public directory before each build to remove draft, expired, and future content.

サイトをデプロイする準備ができたら、以下を実行します。

hugo

This builds your site, publishing the files to the public directory. The directory structure will look something like this:

public/
├── categories/
│   ├── index.html
│   └── index.xml  <-- RSS feed for this section
├── posts/
│   ├── my-first-post/
│   │   └── index.html
│   ├── index.html
│   └── index.xml  <-- RSS feed for this section
├── tags/
│   ├── index.html
│   └── index.xml  <-- RSS feed for this section
├── index.html
├── index.xml      <-- RSS feed for the site
└── sitemap.xml

In a simple hosting environment, where you typically ftp, rsync, or scp your files to the root of a virtual host, the contents of the public directory are all that you need.

Most of our users deploy their sites using a CI/CD workflow, where a push1 to their GitHub or GitLab repository triggers a build and deployment. Popular providers include AWS Amplify, CloudCannon, Cloudflare Pages, GitHub Pages, GitLab Pages, and Netlify.

詳しくは ホスティングとデプロイ の節を参照してください。


  1. The Git repository contains the entire project directory, typically excluding the public directory because the site is built after the push. ↩︎

関連項目

  • Logging
  • クイックスタート
  • 本書以外の学習リソース

このページ内

  • インストールの確認
  • 利用可能なコマンドの表示
  • サイトの構築
  • Draft, future, and expired content
  • サイトの開発とテスト
  • サイトのデプロイ
最終更新日付: 0001/01/01
ページの変更
Hugo 作者より
Hugo Logo
  • Issue 報告
  • ヘルプ
  • @GoHugoIO
  • @spf13
  • @bepsays
 

Hugo Sponsors

Route4Me
Your Company?
 

The Hugo logos are copyright © Steve Francia 2013–2024.

The Hugo Gopher is based on an original work by Renée French.

  • ニュース
  • ドキュメント
  • テーマ
  • コミュニティ
  • GitHub
  • Hugo について
  • インストール
  • はじめよう
  • クイックリファレンス
  • コンテント管理
  • テンプレート
  • 関数
  • メソッド
  • レンダーフック
  • Hugo モジュール
  • Hugo パイプ
  • CLI
  • トラブルシューティング
  • 開発ツール
  • ホスティングと開発
  • 貢献
  • メンテナンス