Skip to content

Commit e5be9ab

Browse files
authored
Merge pull request #79 from extractus/6.2.0
v6.2.0
2 parents 220217f + b2e9336 commit e5be9ab

File tree

8 files changed

+939
-11
lines changed

8 files changed

+939
-11
lines changed

dist/cjs/feed-extractor.js

Lines changed: 5 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/cjs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"name": "@extractus/feed-extractor",
3-
"version": "6.1.9",
3+
"version": "6.2.0",
44
"main": "./feed-extractor.js"
55
}

dist/feed-extractor.esm.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// @extractus/feed-extractor@6.1.9, by @extractus - built with esbuild at 2023-01-04T04:09:49.802Z - published under MIT license
1+
// @extractus/feed-extractor@6.2.0, by @extractus - built with esbuild at 2023-01-04T04:59:05.957Z - published under MIT license
22
var __create = Object.create;
33
var __defProp = Object.defineProperty;
44
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -2003,7 +2003,7 @@ var getLink = (val = [], id = "") => {
20032003
if (id && isValid(id)) {
20042004
return id;
20052005
}
2006-
if (isObject(id) && hasProperty(id, "@_isPermaLink") && Boolean(id["@_isPermaLink"]) === true) {
2006+
if (isObject(id) && hasProperty(id, "@_isPermaLink") && id["@_isPermaLink"] === "true") {
20072007
return getText(id);
20082008
}
20092009
const getEntryLink = (links) => {
@@ -2233,13 +2233,15 @@ var transform3 = (item, options) => {
22332233
const {
22342234
id = "",
22352235
title = "",
2236+
issued = "",
2237+
modified = "",
22362238
updated = "",
22372239
published = "",
22382240
link = "",
22392241
summary = "",
22402242
content = ""
22412243
} = item;
2242-
const pubDate = updated || published;
2244+
const pubDate = updated || modified || published || issued;
22432245
const htmlContent = getText(content || summary);
22442246
const entry = {
22452247
id: getEntryId(id, link, pubDate),

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "6.1.9",
2+
"version": "6.2.0",
33
"name": "@extractus/feed-extractor",
44
"description": "To read and normalize RSS/ATOM/JSON feed data",
55
"homepage": "https://github.com/extractus/feed-extractor",

src/main.test.js

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import { readFileSync } from 'fs'
55

66
import nock from 'nock'
77

8-
import { hasProperty } from 'bellajs'
8+
import { hasProperty, isString } from 'bellajs'
99

1010
import { read } from './main.js'
11+
import { isValid as isValidUrl } from './utils/linker.js'
1112

1213
const feedAttrs = 'title link description generator language published entries'.split(' ')
1314
const entryAttrs = 'title link description published id'.split(' ')
@@ -20,6 +21,19 @@ const parseUrl = (url) => {
2021
}
2122
}
2223

24+
const isValidDate = (d) => {
25+
return (new Date(d)).toString() !== 'Invalid Date'
26+
}
27+
28+
const validateProps = (entry) => {
29+
const { id, link, title, published, description } = entry
30+
return isString(description) &&
31+
isString(id) && id !== '' &&
32+
isString(title) && title !== '' &&
33+
isString(link) && isValidUrl(link) &&
34+
isString(published) && isValidDate(published)
35+
}
36+
2337
describe('test read() function with common issues', () => {
2438
test('read feed from a non-string link', () => {
2539
expect(read([])).rejects.toThrow(new Error('Input param must be a valid URL'))
@@ -76,6 +90,7 @@ describe('test read() standard feed', (done) => {
7690
entryAttrs.forEach((k) => {
7791
expect(hasProperty(result.entries[0], k)).toBe(true)
7892
})
93+
expect(validateProps(result.entries[0])).toBe(true)
7994
})
8095

8196
test('read atom feed from Google', async () => {
@@ -92,6 +107,7 @@ describe('test read() standard feed', (done) => {
92107
entryAttrs.forEach((k) => {
93108
expect(hasProperty(result.entries[0], k)).toBe(true)
94109
})
110+
expect(validateProps(result.entries[0])).toBe(true)
95111
})
96112

97113
test('read atom feed from Google with extraFields', async () => {
@@ -115,6 +131,7 @@ describe('test read() standard feed', (done) => {
115131
})
116132
expect(hasProperty(result, 'author')).toBe(true)
117133
expect(hasProperty(result.entries[0], 'id')).toBe(true)
134+
expect(validateProps(result.entries[0])).toBe(true)
118135
})
119136

120137
test('read atom feed which contains multi links', async () => {
@@ -131,6 +148,7 @@ describe('test read() standard feed', (done) => {
131148
entryAttrs.forEach((k) => {
132149
expect(hasProperty(result.entries[0], k)).toBe(true)
133150
})
151+
expect(validateProps(result.entries[0])).toBe(true)
134152
})
135153

136154
test('read json feed from Micro.blog', async () => {
@@ -147,6 +165,7 @@ describe('test read() standard feed', (done) => {
147165
entryAttrs.forEach((k) => {
148166
expect(hasProperty(result.entries[0], k)).toBe(true)
149167
})
168+
expect(validateProps(result.entries[0])).toBe(true)
150169
})
151170

152171
test('read json feed from Micro.blog with extra fields', async () => {
@@ -170,6 +189,24 @@ describe('test read() standard feed', (done) => {
170189
})
171190
expect(hasProperty(result, 'icon')).toBe(true)
172191
expect(hasProperty(result.entries[0], 'id')).toBe(true)
192+
expect(validateProps(result.entries[0])).toBe(true)
193+
})
194+
195+
test('read rss feed from huggingface.co (no link)', async () => {
196+
const url = 'https://huggingface.co/no-link/rss'
197+
const xml = readFileSync('test-data/rss-feed-miss-link.xml', 'utf8')
198+
const { baseUrl, path } = parseUrl(url)
199+
nock(baseUrl).get(path).reply(200, xml, {
200+
'Content-Type': 'application/xml'
201+
})
202+
const result = await read(url)
203+
feedAttrs.forEach((k) => {
204+
expect(hasProperty(result, k)).toBe(true)
205+
})
206+
entryAttrs.forEach((k) => {
207+
expect(hasProperty(result.entries[0], k)).toBe(true)
208+
})
209+
expect(validateProps(result.entries[0])).toBe(true)
173210
})
174211
})
175212

src/utils/normalizer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export const getLink = (val = [], id = '') => {
3535
if (id && isValidUrl(id)) {
3636
return id
3737
}
38-
if (isObject(id) && hasProperty(id, '@_isPermaLink') && Boolean(id['@_isPermaLink']) === true) {
38+
if (isObject(id) && hasProperty(id, '@_isPermaLink') && id['@_isPermaLink'] === 'true') {
3939
return getText(id)
4040
}
4141
const getEntryLink = (links) => {

src/utils/parseAtomFeed.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,16 @@ const transform = (item, options) => {
2323
const {
2424
id = '',
2525
title = '',
26+
issued = '',
27+
modified = '',
2628
updated = '',
2729
published = '',
2830
link = '',
2931
summary = '',
3032
content = ''
3133
} = item
3234

33-
const pubDate = updated || published
35+
const pubDate = updated || modified || published || issued
3436
const htmlContent = getText(content || summary)
3537
const entry = {
3638
id: getEntryId(id, link, pubDate),

0 commit comments

Comments
 (0)