設定ファイル(hugo.toml)
1# /hugo.toml もしくは
2# /config/_default/hugo.toml
3
4baseURL = "https://example.com/sub/"
5title = "サイト全体のタイトル"
6theme = ["テーマ名"]
7contentDir = "content"
8publishDir = "public"
9resourceDir = "resources"
10
11# サイト言語の設定
12defaultContentLanguage = "ja"
13defaultContentLanguageInSubdir = false
14hasCJKLanguage = true
15
16# サイトのオプション
17enableEmoji = true
18enableGitInfo = false
19enableMissingTranslationPlaceholder = true
20enableRobotsTXT = true
21
22# ビルド時のオプション設定
23buildDrafts = true
24buildFuture = true
25timeout = "50s"
26
27# ビルドするファイルの設定
28[outputs]
29home = ["HTML", "RSS", "JSON"]
30
31# GAの設定
32[services]
33[services.googleAnalytics]
34ID = "G-測定タグID"
35
36# プライバシー設定
37[privacy]
38[privacy.googleAnalytics]
39disable = true
40respectDoNotTrack = true
サイトの設定はhugo.tomlに記述します。
設定の形式はTOML / YAML / JSONが利用できます。
僕はTOML形式を使っています。
permalinks / taxonomies / paginationなどのセクションもhugo.tomlに書けますが、
設定ファイルを分割したい方法で、セクションごとに別ファイルにするのがオススメです。
それぞれの詳しい設定は各セクションのページを参照してください。
注意
v0.110からデフォルトの設定ファイル名がhugo.tomlに変更されました。
しばらくはconfig.tomlも使えるようですが、hugo.tomlに変更することが推奨されています。
詳しくはhugo.toml vs config.toml - Hugoドキュメントを参照してください。
設定セクション名
設定できるセクション(root configuration keys)は
buildcachescascadedeploymentfrontmatterimaginglanguagesmarkupmediatypesmenusminifymoduleoutputformatsoutputsparamspermalinksprivacyrelatedsecuritysegmentsserverservicessitemaptaxonomies
です。
たくさんのセクションがありますが、 すべてにHugoのデフォルト設定が用意されています。 カスタムしたいセクションのみ設定ファイルに追加すればOKです。
出力形式を追加したい([outputFormats])
1[outputs]
2home = ["HTML", "RSS", "JSON"]
3
4[outputFormats]
5[outputFormats.json]
6mediaType = "application/json"
7baseName = "index"
[outputs]セクションで、kind(home / page / sectionなど)ごとに出力する形式(HTML / RSSなど)を設定できます。
デフォルトにない形式を使いたい場合は、[outputFormats]セクションで自作の出力形式を定義します。
上記サンプルはトップページ用にJSON出力を追加する例です。
mediaTypeでMIMEタイプ、baseNameで出力ファイル名(拡張子なし)を指定します。
homeに"JSON"(outputFormats.jsonの名前を大文字にしたもの)を追加すると、/index.jsonが生成されます。
出力形式に対応するテンプレートは/layouts/{kind}.{outputFormat}.{拡張子}のように命名します(例:/layouts/index.json.json)。