Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feed plugin: Add options info.image, info.icon and info.color #723

Merged
merged 1 commit into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ Go to the `v1` branch to see the changelog of Lume 1.
- New `--hostname` argument to `lume --serve` and `lume cms` to change the default
`localhost` value to something else.
- New `--open, -o` argument to `lume cms` to open automatically in the browser.
- Feed plugin
- New option `info.image`
- New option `info.icon`
- New option `info.color`

### Changed
- `inline`: Append classes to existing ones. [#722]
Expand Down
23 changes: 23 additions & 0 deletions plugins/feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ export interface FeedInfoOptions {

/** The feed author URL */
authorUrl?: string;

/** The main image of the site */
image?: string;

/** The logotype or icon of the site */
icon?: string;

/** The color theme of the site */
color?: string;
}

export interface FeedItemOptions {
Expand Down Expand Up @@ -131,6 +140,9 @@ export interface FeedData {
generator?: string;
items: FeedItem[];
author?: Author;
image?: string;
icon?: string;
color?: string;
}

export interface FeedItem {
Expand Down Expand Up @@ -179,6 +191,9 @@ export function feed(userOptions?: Options) {
? defaultGenerator
: info.generator || undefined,
author: getAuthor(rootData, info),
image: info.image,
icon: info.icon,
color: info.color,
items: pages.map((data): FeedItem => {
const content = getDataValue(data, items.content)?.toString();
const pageUrl = site.url(data.url, true);
Expand Down Expand Up @@ -260,6 +275,7 @@ function generateRss(data: FeedData, file: string): string {
"@xmlns:atom": "http://www.w3.org/2005/Atom",
"@xmlns:sy": "http://purl.org/rss/1.0/modules/syndication/",
"@xmlns:slash": "http://purl.org/rss/1.0/modules/slash/",
"@xmlns:webfeeds": "http://webfeeds.org/rss/1.0",
"@version": "2.0",
channel: {
title: data.title,
Expand All @@ -277,6 +293,11 @@ function generateRss(data: FeedData, file: string): string {
name: data.author?.name,
uri: data.author?.url,
},
"webfeeds:cover": {
"@image": data.image,
},
"webfeeds:logo": data.icon,
"webfeeds:accentColor": data.color,
item: data.items.map((item) => ({
title: item.title,
link: item.url,
Expand Down Expand Up @@ -311,6 +332,8 @@ function generateJson(data: FeedData, file: string): string {
feed_url: file,
description: data.description,
author: data.author,
icon: data.image,
favicon: data.icon,
items: data.items.map((item) => ({
id: item.url,
url: item.url,
Expand Down
14 changes: 10 additions & 4 deletions tests/__snapshots__/feed.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ snapshot[`RSS plugin 2`] = `[]`;
snapshot[`RSS plugin 3`] = `
[
{
content: '{"version":"https://jsonfeed.org/version/1","title":"My RSS Feed","home_page_url":"https://example.com/","feed_url":"https://example.com/feed.json","author":{"name":"Laura Rubio"},"items":[{"id":"https://example.com/page5/","url":"https://example.com/page5/","title":"PAGE 5","author":{"name":"Óscar","url":"https://oscarotero.com"},"content_html":"Content of Page 5","date_published":"Thu, 21 Jun 1979 23:45:00 GMT","date_modified":"Thu, 21 Jun 1979 23:45:00 GMT"}]}',
content: '{"version":"https://jsonfeed.org/version/1","title":"My RSS Feed","home_page_url":"https://example.com/","feed_url":"https://example.com/feed.json","author":{"name":"Laura Rubio"},"icon":"https://example.com/image.png","favicon":"https://example.com/icon.svg","items":[{"id":"https://example.com/page5/","url":"https://example.com/page5/","title":"PAGE 5","author":{"name":"Óscar","url":"https://oscarotero.com"},"content_html":"Content of Page 5","date_published":"Thu, 21 Jun 1979 23:45:00 GMT","date_modified":"Thu, 21 Jun 1979 23:45:00 GMT"}]}',
data: {
basename: "feed",
content: '{"version":"https://jsonfeed.org/version/1","title":"My RSS Feed","home_page_url":"https://example.com/","feed_url":"https://example.com/feed.json","author":{"name":"Laura Rubio"},"items":[{"id":"https://example.com/page5/","url":"https://example.com/page5/","title":"PAGE 5","author":{"name":"Óscar","url":"https://oscarotero.com"},"content_html":"Content of Page 5","date_published":"Thu, 21 Jun 1979 23:45:00 GMT","date_modified":"Thu, 21 Jun 1979 23:45:00 GMT"}]}',
content: '{"version":"https://jsonfeed.org/version/1","title":"My RSS Feed","home_page_url":"https://example.com/","feed_url":"https://example.com/feed.json","author":{"name":"Laura Rubio"},"icon":"https://example.com/image.png","favicon":"https://example.com/icon.svg","items":[{"id":"https://example.com/page5/","url":"https://example.com/page5/","title":"PAGE 5","author":{"name":"Óscar","url":"https://oscarotero.com"},"content_html":"Content of Page 5","date_published":"Thu, 21 Jun 1979 23:45:00 GMT","date_modified":"Thu, 21 Jun 1979 23:45:00 GMT"}]}',
page: [
"src",
"data",
Expand All @@ -137,7 +137,7 @@ snapshot[`RSS plugin 3`] = `
},
{
content: '<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" version="2.0">
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:webfeeds="http://webfeeds.org/rss/1.0" version="2.0">
<channel>
<title>My RSS Feed</title>
<link>https://example.com/</link>
Expand All @@ -148,6 +148,9 @@ snapshot[`RSS plugin 3`] = `
<author>
<name>Laura Rubio</name>
</author>
<webfeeds:cover image="https://example.com/image.png"/>
<webfeeds:logo>https://example.com/icon.svg</webfeeds:logo>
<webfeeds:accentColor>#ff0000</webfeeds:accentColor>
<item>
<title>PAGE 5</title>
<link>https://example.com/page5/</link>
Expand All @@ -165,7 +168,7 @@ snapshot[`RSS plugin 3`] = `
data: {
basename: "feed",
content: '<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" version="2.0">
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:webfeeds="http://webfeeds.org/rss/1.0" version="2.0">
<channel>
<title>My RSS Feed</title>
<link>https://example.com/</link>
Expand All @@ -176,6 +179,9 @@ snapshot[`RSS plugin 3`] = `
<author>
<name>Laura Rubio</name>
</author>
<webfeeds:cover image="https://example.com/image.png"/>
<webfeeds:logo>https://example.com/icon.svg</webfeeds:logo>
<webfeeds:accentColor>#ff0000</webfeeds:accentColor>
<item>
<title>PAGE 5</title>
<link>https://example.com/page5/</link>
Expand Down
3 changes: 3 additions & 0 deletions tests/feed.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ Deno.test("RSS plugin", async (t) => {
published: new Date("2020-01-01"),
generator: "https://lume.land",
authorName: "Laura Rubio",
icon: "https://example.com/icon.svg",
image: "https://example.com/image.png",
color: "#ff0000",
},
items: {
title: (data) => data.title?.toUpperCase(),
Expand Down