基本操作
インストールの確認
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 を設定します。
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
draftvalue istrue - The
dateis in the future - The
publishDateis in the future - The
expiryDateis in the past
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.
サイトの開発とテスト
レイアウト開発やコンテントの生成中にサイトを確認したい場合は、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
サイトのデプロイ
サイトをデプロイする準備ができたら、以下を実行します。
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.
詳しくは ホスティングとデプロイ の節を参照してください。
-
The Git repository contains the entire project directory, typically excluding the public directory because the site is built after the push. ↩︎