From 4702666cd7a6c69c5df873f850181ad6b716e5d5 Mon Sep 17 00:00:00 2001 From: Zsolt Szabo Date: Sun, 17 Feb 2019 18:18:50 +0100 Subject: [PATCH] add optional language field --- README.md | 1 + src/__tests__/__snapshots__/rss2.spec.ts.snap | 1 + src/__tests__/setup.ts | 1 + src/rss2.ts | 10 ++++++++++ src/types/index.ts | 1 + 5 files changed, 14 insertions(+) diff --git a/README.md b/README.md index 6645b17..78be424 100755 --- a/README.md +++ b/README.md @@ -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", diff --git a/src/__tests__/__snapshots__/rss2.spec.ts.snap b/src/__tests__/__snapshots__/rss2.spec.ts.snap index b7ee137..c7af68f 100644 --- a/src/__tests__/__snapshots__/rss2.spec.ts.snap +++ b/src/__tests__/__snapshots__/rss2.spec.ts.snap @@ -10,6 +10,7 @@ exports[`rss 2.0 should generate a valid feed 1`] = ` Sat, 13 Jul 2013 23:00:00 GMT http://blogs.law.harvard.edu/tech/rss https://github.com/jpmonette/feed + en Feed Title http://example.com/image.png diff --git a/src/__tests__/setup.ts b/src/__tests__/setup.ts index b4c9aa1..575c53a 100644 --- a/src/__tests__/setup.ts +++ b/src/__tests__/setup.ts @@ -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 diff --git a/src/rss2.ts b/src/rss2.ts index 0f383e4..0c01226 100644 --- a/src/rss2.ts +++ b/src/rss2.ts @@ -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 diff --git a/src/types/index.ts b/src/types/index.ts index 1d4aa55..25baaa0 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -31,6 +31,7 @@ interface FeedOptions { title: string; updated?: Date; generator?: string; + language?: string; feed?: string; feedLinks: any;