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