<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>{{ siteConfig.title }}</title>
  {%- if siteConfig.subtitle %}
  <subtitle>{{ siteConfig.subtitle }}</subtitle>
  {%- endif %}
  {%- if themeConfig.avatar %}
  <icon>{{ getURL(themeConfig.avatar) }}</icon>
  {%- endif %}
  <link rel="self" type="application/atom+xml" href="{{ getURL(siteConfig.feed.path or "atom.xml") }}" />
  {%- if siteConfig.feed.hub %}
  <link rel="hub" href="{{ siteConfig.feed.hub }}" />
  {%- endif %}
  <link rel="alternate" type="text/html" href="{{ getURL() }}" />
  {#-
    The best way should be iterating over all posts to get the latest updated
    post, but actually RFC 4287 only says "when an entry or feed was modified in
    a way the publisher considers significant", so make it simple. It should not
    leads into problems, RSS readers should check posts for which one is updated
    instead of this.
  #}
  <updated>{{ decorated.toISOString() }}</updated>
  <id>{{ getURL() }}</id>
  {%- if siteConfig.author or siteConfig.email %}
  <author>
    {%- if siteConfig.author %}
    <name>{{ siteConfig.author }}</name>
    {%- endif %}
    {%- if siteConfig.email %}
    <email>{{ siteConfig.email }}</email>
    {%- endif %}
  </author>
  {%- endif %}
  <generator uri="https://github.com/AlynxZhou/hikaru-generator-feed/" version="v{{ getFeedGeneratorVersion() }}">Hikaru Generator Feed</generator>
  {%- if site.posts and site.posts.length > 0 %}
  {%- if siteConfig.feed.limit %}
  {%- set posts = site.posts.slice(0, siteConfig.feed.limit) %}
  {%- else %}
  {%- set posts = site.posts %}
  {%- endif %}
  {%- for post in posts %}
  {%- if post.feed !== false %}
  <entry>
    <title>{{ post.title }}</title>
    <link rel="alternate" type="text/html" href="{{ getURL(post.docPath) }}" />
    <id>{{ getURL(post.docPath) }}</id>
    {%- if post.author or post.email %}
    <author>
      {%- if post.author %}
      <name>{{ post.author }}</name>
      {%- endif %}
      {%- if post.email %}
      <email>{{ post.email }}</email>
      {%- endif %}
    </author>
    {%- elseif siteConfig.author or siteConfig.email %}
    <author>
      {%- if siteConfig.author %}
      <name>{{ siteConfig.author }}</name>
      {%- endif %}
      {%- if siteConfig.email %}
      <email>{{ siteConfig.email }}</email>
      {%- endif %}
    </author>
    {%- endif %}
    {%- if post.created %}
    <published>{{ post.created.toISOString() }}</published>
    {%- endif %}
    {%- if post.updated %}
    <updated>{{ post.updated.toISOString() }}</updated>
    {%- elseif post.created %}
    {#- `updated` is always required even there is already a `published`. #}
    <updated>{{ post.created.toISOString() }}</updated>
    {%- endif %}
    {%- if post.excerpt %}
    <summary type="html">
      {{ escapeHTML(post.excerpt) | safe }}
    </summary>
    {%- elseif post.description %}
    <summary type="html">
      {{ escapeHTML(post.description) | safe }}
    </summary>
    {%- elseif post.content %}
    <summary type="html">
      {{ escapeHTML((post.content | striptags).substring(0, siteConfig.feed.contentLimit)) | safe }}…
    </summary>
    {%- endif %}
    {%- if siteConfig.feed.content and post.content %}
    <content type="html">
      {{ escapeHTML(post.content) | safe }}
    </content>
    {%- endif %}
    {%- for category in post.categories %}
    <category term="{{ category.name }}" label="{{ category.name }}" scheme="{{ getURL(category.docPath) }}" />
    {%- endfor %}
    {%- for tag in post.tags %}
    <category term="{{ tag.name }}" label="{{ tag.name }}" scheme="{{ getURL(tag.docPath) }}" />
    {%- endfor %}
  </entry>
  {%- endif %}
  {%- endfor %}
  {%- endif %}
</feed>
