Skip to content

Commit

Permalink
parser fix, version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
kunalpanchal committed May 18, 2019
1 parent 211e45d commit c8cc36b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
32 changes: 26 additions & 6 deletions lib/resources/medium/parser.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,37 @@
const getItems = rssFeed => {
let feedAttrs = ['title', 'link', 'guid', 'dc:creator', 'pubDate', 'content:encoded']
let feedAttrs = [
{
name: 'title',
feedKey: 'title'
}, {
name: 'link',
feedKey: 'link'
}, {
name: 'guid',
feedKey: 'guid'
}, {
name: 'author',
feedKey: 'dc:creator'
}, {
name: 'publishData',
feedKey: 'pubDate'
}, {
name: 'content',
feedKey: 'content:encoded'
}
]

const itemExtractor = (feedItem, tagName) => {
const getItems = rssFeed => {
const itemExtractor = (feedItem, feedKey) => {
return feedItem
.match(new RegExp(`(<${tagName}[^>]*>(.|\n)*?<\/${tagName}>)`, 'gm'))[0]
.replace(new RegExp(`(<${tagName}[^>]*>|</${tagName}>)`, 'gm'), '')
.match(new RegExp(`(<${feedKey}[^>]*>(.|\n)*?<\/${feedKey}>)`, 'gm'))[0]
.replace(new RegExp(`(<${feedKey}[^>]*>|</${feedKey}>)`, 'gm'), '')
.replace(new RegExp(`(<!\\[CDATA\\[|\\]\\]>)`, 'gm'), '')
}

let items = rssFeed.match(/<item>(.|\n)*?<\/item>/gm)
return items.map(feedItem => {
let obj = {}
feedAttrs.map(item => obj[item] = itemExtractor(feedItem, item))
feedAttrs.map(item => obj[item.name] = itemExtractor(feedItem, item.feedKey))
return obj;
})
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@shaai/core",
"version": "0.5.0",
"version": "0.5.1",
"description": "A blogging npm",
"main": "dist/es5/lib/index.js",
"preferGlobal": true,
Expand Down

0 comments on commit c8cc36b

Please sign in to comment.