{{- $url := .Site.Params.cveFeedBucket -}}
{{- $feed := "" -}}

{{- $url := .Site.Params.cveFeedBucket -}}
{{- with try (resources.GetRemote $url) }}
  {{- with .Err -}}
    {{- if eq hugo.Environment "production" -}}
      {{- errorf "%s" . -}}
    {{- else -}}
      {{- warnf "%s" . -}}
    {{- end -}}
  {{- else with .Value -}}
    {{- $feed = .Content | transform.Unmarshal -}}
  {{- else -}}
    {{- $message := printf "Failed to retrieve CVE data from %s (no further error details available)" $url -}}
    {{- if eq hugo.Environment "production" -}}
      {{- errorf $message -}}
    {{- else -}}
      {{- warnf $message -}}
    {{- end -}}
  {{- end -}}
{{- end -}}
<!-- Render last build date only if CVE feed is available, accommodating for offline builds. -->
{{- if and (ne $feed nil) (ne (printf "%T" $feed) "string") -}}
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>{{ $feed.title }}</title>
    <link>{{ .Site.BaseURL }}docs/reference/issues-security/official-cve-feed/</link>
    <description>{{ $feed.description }}</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-US</language>
	<copyright>{{ .Site.Params.Copyright_k8s }}</copyright>
    <lastBuildDate>{{ time.Format "Mon, 02 Jan 2006 15:04:05 -0700" $feed._kubernetes_io.updated_at | safeHTML }}</lastBuildDate>
    {{ with .OutputFormats.Get "RSS" -}}
	{{ printf "<atom:link href=%q rel=\"self\" type=%q />" .Permalink .MediaType | safeHTML }}
    {{ end -}}
    {{ range $feed.items -}}
    <item>
      <title>{{ .id }}</title>
      <link>{{ .url }}</link>
      <pubDate>{{ time.Format "Mon, 02 Jan 2006 15:04:05 -0700" .date_published | safeHTML }}</pubDate>
      <guid>{{ .external_url }}</guid>
      <description>{{ htmlEscape .summary }}</description>
      <category term="{{ .status }}" scheme="https://k8s.io/2024-06-27/cve-item-status" />
    </item>
    {{ end -}}
  </channel>
</rss>
{{- end -}}
