Feed

Generate a RSS or JSON Feed automatically for your site

Options See on deno.land

output string string[]

The output filenames

Default:
"/feed.rss"
query string

The query to search the pages

Default:
""
sort string

The sort order

Default:
"date=desc"
limit number

The maximum number of items

Default:
10
info object

The feed info

title string

The feed title

Default:
"My RSS Feed"
subtitle string

The feed subtitle

date object

The feed published date

Default:
new Date()
description string

The feed description

Default:
""
lang string

The feed language

Default:
"en"
generator string boolean

The feed generator. Set true to generate automatically

Default:
true
items object

The feed items configuration

title string

The item title

Default:
"=title"
description string

The item description

Default:
"=description"
date string

The item date

Default:
"=date"
content string

The item content

Default:
"=children"
lang string

The item language

Default:
"=lang"

Description

This plugin generates RSS or JSON feeds automatically with any page collection (like posts, articles, events, etc).

Installation

Import this plugin in your _config.ts file to use it:

import lume from "lume/mod.ts";
import feed from "lume/plugins/feed.ts";

const site = lume();

site.use(feed({
  output: ["/posts.rss", "/posts.json"],
  query: "type=post",
  info: {
    title: "=site.title",
    description: "=site.description",
  },
  items: {
    title: "=title",
    description: "=excerpt",
  },
}));

export default site;

Configuration

Internally, this plugin uses Search to search and return the pages, so you have to provide a query to search the pages and optionally the sort and limit parameters.

You need to configure also the generic data of the feed (in the info key) and the info of the items (in the items key). This is an example with all available options:

site.use(feed({
  output: ["/posts.rss", "/posts.json"], // The file or files that must be generated
  query: "type=post", // Select only pages of type=post
  sort: "date=desc", // To sort by data in ascendent order
  limit: 10, // To show only the 10 first results
  info: {
    title: "My blog", // The feed title
    description: "Where I put my thoughts", // The feed subtitle
    date: new Date(), // The publish date
    lang: "en", // The language of the feed
    generator: true, // Set `true` to automatically generate the "Lume {version}"
  },
  items: {
    title: "=title", // The title of every item
    description: "=excerpt", // The description of every item
    date: "=date", // The published date of every item
    content: "=children", // The content of every item
    lang: "=lang", // The language of every item
  },
}));

The options info and items use the same aliases as metas plugin: any value starting with = represents a variable name that will be used to extract this info. For example, the description of the items has the value =excerpt, which means every item will use the value of the variable excerpt for the description.

It's also possible to extract the info using CSS selectors. For example, let's say we want to generate a RSS with the same content as the div .post-content. We just have to start the value of the code with $:

site.use(feed({
  // general config
  info: {
    // info config
  },
  items: {
    title: "=title",
    description: "=excerpt",
    date: "=date",
    content: "$.post-content", // Use the content of .post-content element
    lang: "=lang",
  },
}));

If you want to create more than one feed, just use the plugin once per feed:

site.use(feed({
  output: "/posts.rss",
  // Posts feed configuration
}));

site.use(feed({
  output: "/articles.rss",
  // Articles feed configuration
}));