HUGO
Menu
GitHub 87548 stars Mastodon

OutputFormats

返回 OutputFormat 對象的切片,每個代表為給定頁面啟用的輸出格式之一。

Syntax

PAGE.OutputFormats

Returns

[]OutputFormat

output format(輸出格式)是一組設置,定義 Hugo 在構建網站時如何渲染文件。例如,htmljson �?rss 是內置輸出格式。您可以創建多個輸出格式,並根據 page kind(頁面類型)控制它們的生成,或通過為特定頁面啟用一個或多個輸出格式�

Page 對象上的 OutputFormats 方法返回 OutputFormat 對象的切片,每個代表為給定頁面啟用的輸出格式之一。詳見 詳情

方法

Canonical

New in v0.154.4

(page.OutputFormat) 返回當前頁面的 規范輸出格式(如果已定義)。一旦捕獲了對象,就可以使用其任何 關聯方法

{{ with .Site.Home.OutputFormats.Canonical }}
  {{ .MediaType.Type }} → text/html
  {{ .MediaType.MainType }} → text
  {{ .MediaType.SubType }} → html
  {{ .Name }} → html
  {{ .Permalink }} → https://example.org/
  {{ .Rel }} → canonical
  {{ .RelPermalink }} → /
{{ end }}

Get

(page.OutputFormat) 返回具有給定標識符的 OutputFormat 對象。一旦捕獲了對象,就可以使用其任何 關聯方法

{{ with .Site.Home.OutputFormats.Get "rss" }}
  {{ .MediaType.Type }} → application/rss+xml
  {{ .MediaType.MainType }} → application
  {{ .MediaType.SubType }} → rss
  {{ .Name }} → rss
  {{ .Permalink }} → https://example.org/index.xml
  {{ .Rel }} → alternate
  {{ .RelPermalink }} → /index.xml
{{ end }}

示例

渲染指向當前頁面 規范輸出格式link 元素:

{{ with .OutputFormats.Canonical }}
  {{ printf "<link rel=%q type=%q href=%q>" .Rel .MediaType.Type .Permalink | safeHTML }}
{{ end }}

渲染指向當前頁面 rss 輸出格式的錨元素:

{{ with .OutputFormats.Get "rss" }}
  <a href="{{ .RelPermalink }}">RSS Feed</a>
{{ end }}

請查看 鏈接到輸出格式 部分以了解上述構造的重要性。


Last updated: January 1, 0001
Improve this page