getzola / zola

A fast static site generator in a single binary with everything built-in. https://www.getzola.org
https://www.getzola.org
MIT License
13.78k stars 959 forks source link

Generated Atom/RSS feed is badly generated #2404

Open orowith2os opened 10 months ago

orowith2os commented 10 months ago

Occurs on Zola 0.18.0

When I enable the Atom feed and view its contents, it appears to be very mangled and barebones. For example, the post content is put into the description field; it should be in a content field, and the post description should be in a dedicated description field instead. There's also a summary field. The date of the post is not included. Tags are also not included.

One can see my expectations by taking a peek at the generated Atom feed of most any Jekyll site.

I suppose one could work around this by making their own feed template, but why? Zola should be able to fit this desire itself.

orowith2os commented 10 months ago

This seems like it could be easy enough to fix on my own, just modify the components/templates/src/builtins/rss.xml file. I'll poke at it and bring it up to spec later.

Keats commented 10 months ago

I'm all for better default templates.

Tags are also not included.

We don't have first class tags so users will have to write their own templates for that

orowith2os commented 10 months ago

Is there currently an RFC or PR somewhere to add first class tags? That would improve the usability of a stock Atom feed greatly.

orowith2os commented 10 months ago

Changed the issue to refer to the Atom feed; if anybody wants to work on the RSS feed, go for it, I'll only be focusing on Atom.

Keats commented 10 months ago

No RFC or PR currently. You can make a PR fixing the template directly and link the spec as well

orowith2os commented 10 months ago

I would need several additions to Zola in order to have a compliant (and not-horrible) Atom feed. RSS may prove easier.

Keats commented 10 months ago

Can you list them?

orowith2os commented 10 months ago

Here's what I've got my Atom feed set up as so far.

<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="{{ lang }}">
  <title>{{ config.title }}</title>
  <subtitle>{{ config.description }}</subtitle>

  <rights>
    {% set current_year = now() | date(format="%Y") -%}
    © 2022 - {{ current_year }} {{ config.extra.author }}
  </rights>
  <author>
    <name>{{ config.extra.author }}</name>
    <email>{{ config.extra.email }}</email>
    <uri>{{ config.base_url }}</uri>
  </author>

  <!-- The date here is when I bought oro.gay from Porkbun. -->
  <id>tag:oro.gay,{{ "2024-01-07" | date(format="%F") }}:{{ config.extra.feed_uuid }}</id>

  {# Grab all dates of all posts, find the latest one. -#}
  {% set_global dates = [] -%}
  {% for page in pages -%}
    {% if not page.extra.no_feed -%}
      {% if page.date -%}
        {% set_global dates = dates | concat(with = page.date) -%}
      {% endif -%}
      {% if page.updated -%}
        {% set_global dates = dates | concat(with = page.updated) -%}
      {% endif -%}
    {% endif -%}
  {% endfor -%}
  {% set_global dates = dates | sort() -%}
  <updated>{{ dates | last | date(format="%+") }}</updated>

  <!-- The W3C validator will complain when this is on localhost, disregard. -->
  <link href="{{ feed_url }}" rel="self" type="application/atom+xml"/>
  <link href="{{ config.base_url }}" hreflang="{{ lang }}"/>
  <generator uri="https://www.getzola.org/">Zola</generator>

  {% for page in pages -%}
    {%- if page.date and not page.extra.no_feed -%}
    <entry xml:lang="{{ page.lang }}">
      {% if page.title -%}
        <title>{{ page.title }}</title>
      {%- endif %}
      <published>{{ page.date | date(format="%+") }}</published>
      <updated>{{
        page.updated
        | default(value = page.date)
        | date(format="%+")
      }}</updated>

      <link href="{{ page.permalink }}"
            hreflang="{{ page.lang }}"
            type="text/html"/>
      <id>tag:oro.gay,{{ page.date | date(format="%F") }}:{{ page.extra.uuid }}</id>

      <author>
        <name>{{
            page.extra.author
            | default(value = config.extra.author)
        }}</name>
      </author>
      <rights type="html">
        © {{ page.date | date(format="%Y")}}
        {% if page.updated -%} - {{ page.updated|date(format="%Y") }}
        {% endif -%} {{
          page.extra.author
          | default(value = config.extra.author)
        }}
      </rights>

      {% if page.description -%}
        <summary type="html">
          {{ page.description | escape | safe }}
        </summary>
      {% endif -%}
    <content src="{{ page.permalink }}" type="text/html">
          {{ page.content }}
    </content>
      {% if page.taxonomies is containing("categories") -%}
        {% for tag in page.taxonomies.tags -%}
          <category term="{{ tag }}"/>
        {% endfor -%}
      {% endif -%}
    </entry>
    {% endif -%}
  {% endfor -%}

</feed>
Keats commented 10 months ago

Ah I see, none of those 4 things are going to be added to Zola though :/

orowith2os commented 10 months ago

If that could be changed, many things would be improved significantly.

Gers2017 commented 3 months ago

zola 0.19.1

This is the default rss.xml file generated by zola. In atom feeds, the content field is using the the entire page content (same with the description field in rss feeds) as @orowith2os pointed out. This could potentially affect how the feed is displayed by applications.

I suggest to use the src property to link the page URL. Thank you for considering this request.

huge-blog-post

atom-rss-1