Skip to content

Commit

Permalink
add optional language field
Browse files Browse the repository at this point in the history
  • Loading branch information
zsolt-dev authored and jpmonette committed Feb 25, 2019
1 parent 5da79f1 commit 4702666
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const feed = new Feed({
description: "This is my personal feed!",
id: "http://example.com/",
link: "http://example.com/",
language: "en", // optional, used only in RSS 2.0, possible values: http://www.w3.org/TR/REC-html40/struct/dirlang.html#langcodes
image: "http://example.com/image.png",
favicon: "http://example.com/favicon.ico",
copyright: "All rights reserved 2013, John Doe",
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/__snapshots__/rss2.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ exports[`rss 2.0 should generate a valid feed 1`] = `
<lastBuildDate>Sat, 13 Jul 2013 23:00:00 GMT</lastBuildDate>
<docs>http://blogs.law.harvard.edu/tech/rss</docs>
<generator>https://github.com/jpmonette/feed</generator>
<language>en</language>
<image>
<title>Feed Title</title>
<url>http://example.com/image.png</url>
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const sampleFeed = new Feed({
link: "http://example.com/",
id: "http://example.com/",
feed: "http://example.com/sampleFeed.rss",
language: "en",
image: "http://example.com/image.png",
copyright: "All rights reserved 2013, John Doe",
updated, // optional, default = today
Expand Down
10 changes: 10 additions & 0 deletions src/rss2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ export default (ins: Feed) => {

const rss: any[] = [{ _attr: { version: "2.0" } }, { channel }];

/**
* Channel language
* https://validator.w3.org/feed/docs/rss2.html#ltimagegtSubelementOfLtchannelgt
*/
if (options.language) {
channel.push({
language: options.language
});
}

/**
* Channel Image
* http://cyber.law.harvard.edu/rss/rss.html#ltimagegtSubelementOfLtchannelgt
Expand Down
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ interface FeedOptions {
title: string;
updated?: Date;
generator?: string;
language?: string;

feed?: string;
feedLinks: any;
Expand Down

0 comments on commit 4702666

Please sign in to comment.