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
  • メンテナンス
コンテント管理 基本構成

ビルドオプション

Build options help define how Hugo must treat a given page when building the site.

Build options are stored in a reserved front matter object named build with these defaults:

content/example/index.md
     
---
build:
  list: always
  publishResources: true
  render: always
---
+++
[build]
  list = 'always'
  publishResources = true
  render = 'always'
+++
{
   "build": {
      "list": "always",
      "publishResources": true,
      "render": "always"
   }
}
list
When to include the page within page collections. Specify one of:
  • always
    Include the page in all page collections. For example, site.RegularPages, .Pages, etc. This is the default value.
  • local
    Include the page in local page collections. For example, .RegularPages, .Pages, etc. Use this option to create fully navigable but headless content sections.
  • never
    Do not include the page in any page collection.
publishResources
Applicable to page bundles, determines whether to publish the associated page resources. Specify one of:
  • true
    Always publish resources. This is the default value.
  • false
    Only publish a resource when invoking its Permalink, RelPermalink, or Publish method within a template.
render
When to render the page. Specify one of:
  • always
    Always render the page to disk. This is the default value.
  • link
    Do not render the page to disk, but assign Permalink and RelPermalink values.
  • never
    Never render the page to disk, and exclude it from all page collections.

Any page, regardless of its build options, will always be available by using the .Page.GetPage or .Site.GetPage method.

Example – headless page

Create a unpublished page whose content and resources can be included in other pages.

content/
├── headless/
│   ├── a.jpg
│   ├── b.jpg
│   └── index.md  <-- leaf bundle
└── _index.md     <-- home page

Set the build options in front matter:

content/headless/index.md
     
---
build:
  list: never
  publishResources: false
  render: never
title: Headless page
---
+++
title = 'Headless page'
[build]
  list = 'never'
  publishResources = false
  render = 'never'
+++
{
   "build": {
      "list": "never",
      "publishResources": false,
      "render": "never"
   },
   "title": "Headless page"
}

To include the content and images on the home page:

layouts/_default/home.html
{{ with .Site.GetPage "/headless" }}
  {{ .Content }}
  {{ range .Resources.ByType "image" }}
    <img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
  {{ end }}
{{ end }}

The published site will have this structure:

public/
├── headless/
│   ├── a.jpg
│   └── b.jpg
└── index.html

In the example above, note that:

  1. Hugo did not publish an HTML file for the page.
  2. Despite setting publishResources to false in front matter, Hugo published the page resources because we invoked the RelPermalink method on each resource. This is the expected behavior.

Example – headless section

Create a unpublished section whose content and resources can be included in other pages.

content/
├── headless/
│   ├── note-1/
│   │   ├── a.jpg
│   │   ├── b.jpg
│   │   └── index.md  <-- leaf bundle
│   ├── note-2/
│   │   ├── c.jpg
│   │   ├── d.jpg
│   │   └── index.md  <-- leaf bundle
│   └── _index.md     <-- branch bundle
└── _index.md         <-- home page

Set the build options in front matter, using the cascade keyword to “cascade” the values down to descendant pages.

content/headless/_index.md
     
---
cascade:
- build:
    list: local
    publishResources: false
    render: never
title: Headless section
---
+++
title = 'Headless section'
[[cascade]]
  [cascade.build]
    list = 'local'
    publishResources = false
    render = 'never'
+++
{
   "cascade": [
      {
         "build": {
            "list": "local",
            "publishResources": false,
            "render": "never"
         }
      }
   ],
   "title": "Headless section"
}

In the front matter above, note that we have set list to local to include the descendant pages in local page collections.

To include the content and images on the home page:

layouts/_default/home.html
{{ with .Site.GetPage "/headless" }}
  {{ range .Pages }}
    {{ .Content }}
    {{ range .Resources.ByType "image" }}
      <img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
    {{ end }}
  {{ end }}
{{ end }}

The published site will have this structure:

public/
├── headless/
│   ├── note-1/
│   │   ├── a.jpg
│   │   └── b.jpg
│   └── note-2/
│       ├── c.jpg
│       └── d.jpg
└── index.html

In the example above, note that:

  1. Hugo did not publish an HTML file for the page.
  2. Despite setting publishResources to false in front matter, Hugo correctly published the page resources because we invoked the RelPermalink method on each resource. This is the expected behavior.

Example – list without publishing

Publish a section page without publishing the descendant pages. For example, to create a glossary:

content/
├── glossary/
│   ├── _index.md
│   ├── bar.md
│   ├── baz.md
│   └── foo.md
└── _index.md

Set the build options in front matter, using the cascade keyword to “cascade” the values down to descendant pages.

content/glossary/_index.md
     
---
build:
  render: always
cascade:
- build:
    list: local
    publishResources: false
    render: never
title: Glossary
---
+++
title = 'Glossary'
[build]
  render = 'always'
[[cascade]]
  [cascade.build]
    list = 'local'
    publishResources = false
    render = 'never'
+++
{
   "build": {
      "render": "always"
   },
   "cascade": [
      {
         "build": {
            "list": "local",
            "publishResources": false,
            "render": "never"
         }
      }
   ],
   "title": "Glossary"
}

To render the glossary:

layouts/glossary/list.html
<dl>
  {{ range .Pages }}
    <dt>{{ .Title }}</dt>
    <dd>{{ .Content }}</dd>
  {{ end }}
</dl>

The published site will have this structure:

public/
├── glossary/
│   └── index.html
└── index.html

Example – publish without listing

Publish a section’s descendant pages without publishing the section page itself.

content/
├── books/
│   ├── _index.md
│   ├── book-1.md
│   └── book-2.md
└── _index.md

Set the build options in front matter:

content/books/_index.md
     
---
build:
  list: never
  render: never
title: Books
---
+++
title = 'Books'
[build]
  list = 'never'
  render = 'never'
+++
{
   "build": {
      "list": "never",
      "render": "never"
   },
   "title": "Books"
}

The published site will have this structure:

public/
├── books/
│   ├── book-1/
│   │   └── index.html
│   └── book-2/
│       └── index.html
└── index.html

Example – conditionally hide section

Consider this example. A documentation site has a team of contributors with access to 20 custom shortcodes. Each shortcode takes several arguments, and requires documentation for the contributors to reference when using them.

Instead of external documentation for the shortcodes, include an “internal” section that is hidden when building the production site.

content/
├── internal/
│   ├── shortcodes/
│   │   ├── _index.md
│   │   ├── shortcode-1.md
│   │   └── shortcode-2.md
│   └── _index.md
├── reference/
│   ├── _index.md
│   ├── reference-1.md
│   └── reference-2.md
├── tutorials/
│   ├── _index.md
│   ├── tutorial-1.md
│   └── tutorial-2.md
└── _index.md

Set the build options in front matter, using the cascade keyword to “cascade” the values down to descendant pages, and use the target keyword to target the production environment.

content/internal/_index.md.
     
cascade:
- _target:
    environment: production
  build:
    list: never
    render: never
title: Internal
title = 'Internal'
[[cascade]]
  [cascade._target]
    environment = 'production'
  [cascade.build]
    list = 'never'
    render = 'never'
{
   "cascade": [
      {
         "_target": {
            "environment": "production"
         },
         "build": {
            "list": "never",
            "render": "never"
         }
      }
   ],
   "title": "Internal"
}

The production site will have this structure:

public/
├── reference/
│   ├── reference-1/
│   │   └── index.html
│   ├── reference-2/
│   │   └── index.html
│   └── index.html
├── tutorials/
│   ├── tutorial-1/
│   │   └── index.html
│   ├── tutorial-2/
│   │   └── index.html
│   └── index.html
└── index.html

関連項目

  • アーキタイプ
  • コメント
  • コンテントの構成
  • ショートコード
  • フロントマター

このページ内

  • Example – headless page
  • Example – headless section
  • Example – list without publishing
  • Example – publish without listing
  • Example – conditionally hide section
最終更新日付: 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
  • トラブルシューティング
  • 開発ツール
  • ホスティングと開発
  • 貢献
  • メンテナンス