docusaurus
docusaurus copied to clipboard
Provide ability to filter RSS / Atom feed
Have you read the Contributing Guidelines on issues?
- [X] I have read the Contributing Guidelines on issues.
Description
My blog turns out to be quite large. It was recently brought to my attention that the RSS feed wasn't working well for readers as a consequence.
At present, Docusaurus includes all blog entries in the Atom / RSS feeds: https://docusaurus.io/docs/blog#feed
The proposal is to add another option to support filtering the responses in the feed. This would allow people to reduce the size of their blogs when they become large.
Has this been requested on Canny?
No
Motivation
see description.
API design
Consider the below type with a new filter
option:
type FeedType = 'rss' | 'atom' | 'json';
type BlogOptions = {
feedOptions?: {
type?: FeedType | 'all' | FeedType[] | null;
title?: string;
description?: string;
copyright: string;
language?: string; // possible values: http://www.w3.org/TR/REC-html40/struct/dirlang.html#langcodes
filter?: (blogItem: BlogItem, index: number) => boolean; // **NEW OPTION**
};
};
This could then be used like this:
module.exports = {
// ...
presets: [
[
'@docusaurus/preset-classic',
{
blog: {
feedOptions: {
type: 'all',
filter: (blogItem, index) => index < 20, // only include first 20 entries
},
},
},
],
],
};
Have you tried building it?
~~No - but I would. I've built a workaround in my blog: https://github.com/johnnyreilly/blog.johnnyreilly.com/pull/352~~
Yes: see https://github.com/facebook/docusaurus/pull/8378
Self-service
- [X] I'd be willing to contribute this feature to Docusaurus myself.
These kinds of callback-based APIs are hard to design properly, but I agree with the motivation. Waiting for more ideas from @slorber. I'm wondering: how do other sites handle this? Do they truncate their feeds to the nearest x entries?
From generally looking around there seems to be a latest X entries approach as well as a "paging" approach. Though, from what I've read the paging approach is not well supported.
The approach I've suggested is a filter
- I think a reduce
could also work here to allow folk to mutate the contents in some way too. (Technically you could do that in a filter but it's not considered good practice from an FP perspective)
I've an idea to drive filtering based on the last git commit in a similar fashion to what I do here:
https://blog.johnnyreilly.com/2022/11/25/adding-lastmod-to-sitemap-git-commit-date
Might be nice to update the Atom / RSS feeds based on this too
Did some googling and what I understand=
- our feed can be quite heavy as we include the HTML content
- Atom can support pagination but RSS can't
- readers support an arbitrary number of items/feed size, probably hard to find the lowest common denominator
- Read on a Feedly forum their feed limit is around 8mb
That seems reasonable to add such a feature to me 👍
Resolved by https://github.com/facebook/docusaurus/pull/8378