HUGO
Menu
GitHub 87548 stars Mastodon

AlternativeOutputFormats

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

Syntax

PAGE.AlternativeOutputFormats

Returns

page.OutputFormats

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

Page 對象上的 AlternativeOutputFormats 方法返回 OutputFormat 對象的切片,不包括當前輸出格式,每個代表為給定頁面啟用的一個輸出格式。詳見 輸出格式

例如,為每個替代輸出格式生成 link 元素:

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

Hugo 將其渲染為類似:

<link rel="alternate" type="application/rss+xml" href="https://example.org/index.xml">
<link rel="alternate" type="application/json" href="https://example.org/index.json">

Last updated: January 1, 0001
Improve this page