omz13 / kirby3-feeds

A plugin for kirby3 to generate rss, atom, and json syndication feeds
21 stars 3 forks source link
atom-generator json-generator kirby3-plugin rss-generator syndication

Kirby3 feeds

License Kirby Version Issues

Requirement: Kirby 3.0.0-RC3 or better

Coffee, Beer, etc.

This started as a simple plugin and morphed into something quite complex to cope with a combination of trying to get something sensible out of Kirby while also trying to generate something acceptable within the constraints of the different syndication formats.

This plugin is free but if you use it in a commercial project to show your support you are welcome to:

Documentation

Purpose

For a kirby3 site, this plugin (omz13/feeds) generates syndication feeds in RSS, ATOM, and JSON formats based on a Kirby3 "collection". If a page is given in a collection it will be included in a syndication feed; therefore, ensure that the collection filters "published" or "draft" per your requirements because this plugin does no filtering whatsoever (because you may want to do something like have a feed for drafts). You are in control of what does or does not get put into a feed (and this can be different from what is publically shown on a site).

Caveat:

Client Support

RSS feeds are generally well supported by clients; the ATOM feed offers some extra technical niceties, but client support varies; the JSON format is very new, and client support varies. Here are details of a few clients that I have used:

In terms of client for OS X:

In terms of iOS:

In terms of generic services/clients:

In terms of Windows clients: sorry, I have no idea as inhabit an OS X / iOS world.

Related plugins

For a plugin that provides the methods issunset and isunderembargo, kindly see omz13/kirby3-suncyclepages.

Roadmap

The non-binding list of planned features and implementation notes are:

Installation

Pick one of the following per your epistemological model:

For the record: installation by composer is cool; supporting installation by zip and submodule was an absolute pain, especially as I am an installation by composer person, so do feel guilted into getting me Coffee, Beer, etc., because this is for your benefit and not mine (and yes, I would have have preferred to spend my time somewhere warm and sunny instead of being hunched over a keyboard while the snow falls outside and the thermometer shows no inclination to get above 0C).

Configuration

There are four aspects that need configuration:

site/config/config.php

In your site's site/config/config.php the following entries prefixed with omz13.feeds. can be used:

content/site.txt (via blueprint site/blueprints/site.yml)

The plugin can be explicitly disabled in content/site.txt by having an entry for feeds and setting this to false. This could be achieved through the panel by adding the following into site/blueprints/site.yml:

type:          fields
fields:
  feeds:
    label:     Syndication
    type:      toggle
    default:   off
    text:
      - RSS disabled
      - RSS enabled

If any entry for feeds is not present in content/site.txt, it is assumed that the plugin is not be be disabled (i.e. failsafe to false).

Feed discovery

At a minimum you need to add appropriate feed-discovery links to your site's homepage.

This plugin provides two snippets to dynamically generate the necessary meta data:

Or for those who prefer to use pageMethods, the equivalent to the above are:

Example:

In site/snippets/header.php - or whatever generates your <head> data - simply add <?php snippet('feeds-header') ?> or <?= $page->headFeeds() ?> in the best applicable place.

If the plugin is disabled, these snippets will not generate the appropriate feed-discovery links.

Collections

For the default (firehose) syndication feed, you need to ensure that you have a collection and have configured it. Typically this would be an 'articles' collection, and an example would be:

<?php

return function ($site) {
    return $site->find('blog')->children()->listed()->flip();
};

If using omz13/suncyclepages for embargo and withdraw, this would then be:

<?php

return function ($site) {
        return $site->find('blog')->children()->listed()->isunderembargo(false)->issunset(false)->flip();
};

Use

For example, for the Kirby Starter Kit, the following would be applicable:

<?php

return [
  'omz13.feeds.cacheTTL' => 60,
  'omz13.feeds.firehose' => 'articles',
  ],
];

For experimental purposes this plugin implements a single-level pseudo-namespace. You can mix discrete vs array options, but try not to, and be aware that priority is given to the array variant. The above discrete configuration would therefore become:

<?php

return [
  'omz13.feeds' => [
    'cacheTTL' => 60,
    'firehose' => 'articles',
  ],
];

See Kirby3's issue #761 for more about namespaced options.

Disclaimer

This plugin is provided "as is" with no guarantee. Use it at your own risk and always test it yourself before using it in a production environment. If you find any issues, please create a new issue.