{{- $pctx := . -}}
{{- if .IsHome }}{{ $pctx = .Site }}{{ end -}}
{{- $pages := slice -}}
{{- if or $.IsHome $.IsSection -}}
{{- $pages = $pctx.RegularPages -}}
{{- else -}}
{{- $pages = $pctx.Pages -}}
{{- end -}}
{{- $limit := .Site.Config.Services.RSS.Limit -}}
{{- if ge $limit 1 -}}
{{- $pages = $pages | first $limit -}}
{{- end -}}
{{- printf "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>" | safeHTML }}
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>{{ .Site.Title }}{{ if not .IsHome }}: {{ .LinkTitle | humanize }}{{ end }}</title>
	<description>{{ if not .IsHome }}{{ .Title }} on {{ end }}{{ .Site.Title }}</description>
    <link>{{ .Permalink }}</link>
    <language>{{ site.Language.LanguageCode }}</language>{{ if site.Params.email }}
	<managingEditor>{{ site.Params.email }}</managingEditor>{{ end }}
    <lastBuildDate>{{ (index $pages.ByLastmod.Reverse 0).Lastmod.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</lastBuildDate>
    {{ with .OutputFormats.Get "RSS" -}}
    {{ printf "<atom:link href=%q rel=\"self\" type=%q />" .Permalink .MediaType | safeHTML }}
    {{- end }}
    {{- range $pages }}
    <item>
      <title>{{ .Title }}</title>
      <link>{{ .Permalink }}</link>
      <pubDate>{{ .PublishDate.Format "Mon, 02 Jan 2006 15:04:05 -0700" | safeHTML }}</pubDate>{{ if site.Params.email }}
	  <author>{{ site.Params.email }}</author>{{ end }}
      <guid>{{ .Permalink }}</guid>
      <description>{{ .Content | transform.XMLEscape | safeHTML }}</description>
    </item>
    {{- end }}
  </channel>
</rss>