AlternativeOutputFormats 替代输出格式

AlternativeOutputFormats 替代输出格式


Returns a slice of OutputFormat objects, excluding the current output format, each representing one of the output formats enabled for the given page. 返回一组 OutputFormat 对象(不包括当前输出格式),每个对象代表给定页面启用的输出格式之一。

The AlternativeOutputFormats method on a Page object returns a slice of OutputFormat objects, excluding the current output format, each representing one of the output formats enabled for the given page.. See 

AlternativeOutputFormats对象上的方法返回对象Page切片OutputFormat(不包括当前输出格式),每个对象代表给定页面启用的输出格式之一

Methods 方法 #

Example 例子 #

Generate a link element in the <head> of each page for each of the alternative output formats:

<head>
  ...
  {{ $title := printf "%s | %s" .Title site.Title }}
  {{ if .IsHome }}
    {{ $title = site.Title }}
  {{ end }}
  {{ range .AlternativeOutputFormats -}}
    {{ printf `<link rel=%q type=%q href=%q title=%q>` .Rel .MediaType.Type .Permalink $title | safeHTML }}
  {{ end }}
  ...
</head>

On the site’s home page, Hugo renders this to:

<link rel="alternate" type="application/rss+xml" href="https://example.org/index.xml" title="ABC Widgets, Inc.">