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.71k stars 953 forks source link

Both RSS and Atom feeds? #2083

Open orlp opened 1 year ago

orlp commented 1 year ago

Is there a way to support having both an Atom and an RSS feed at the same time?

Keats commented 1 year ago

Not right now no

dennisse commented 1 year ago

You can create a new template to achieve this.

Just create a template for a feed, and use the get_section-function (https://www.getzola.org/documentation/templates/overview/#get-section) to get the root section and use it. Then create a new post/page under content, give it the correct path of your new rss-feed, and set its template to the new template.

Here is an example-template for a new atom-feed, feed.xml:

<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="{{ lang }}">
    <title>{{ config.title }}
        {%- if term %} - {{ term.name }}
    {%- elif section.title %} - {{ section.title }}
        {%- endif -%}
    </title>
    {%- if config.description %}
    <subtitle>{{ config.description }}</subtitle>
    {%- endif %}
    {%- if not feed_url is defined %}
        {%- set feed_url = page.permalink %}
    {% endif %}
    <link href="{{ feed_url | safe }}" rel="self" type="application/atom+xml"/>
  <link href="
      {%- if section -%}
        {{ section.permalink | escape_xml | safe }}
      {%- else -%}
        {{ config.base_url | escape_xml | safe }}
      {%- endif -%}
    "/>
    <generator uri="https://www.getzola.org/">Zola</generator>
    <updated>{{ last_updated | default(value=now()) | date(format="%+") }}</updated>
    <id>{{ feed_url | safe }}</id>
    {%- if not pages is defined %}
        {%- set getpages = get_section(path="_index.md") %}
        {%- set pages = getpages.pages %}
    {%- endif %}
    {%- for p in pages %}
    {%- if not p.relative_path is starting_with("pages/") %}
    <entry xml:lang="{{ p.lang }}">
        <title>{{ p.title }}</title>
        <published>{{ p.date | date(format="%+") }}</published>
        <updated>{{ p.updated | default(value=p.date) | date(format="%+") }}</updated>
        <link rel="alternate" href="{{ p.permalink | safe }}" type="text/html"/>
        <id>{{ p.permalink | safe }}</id>
        <content type="html">{{ p.content }}</content>
    </entry>
    {%- endif %}
    {%- endfor %}
</feed>

And then I create the page content/pages/feed.xml.md with this content:

+++
template = "feed.xml"
path = "feed.xml"
+++

This can be used in addition to whatever feed you've already defined.

sjehuda commented 11 months ago

@dennisse an XSLT stylesheet would be a nice addition too https://gitgud.io/sjehuda/streamburner (you can ignore the CSS file there and add another one.