Skip to content

Instantly share code, notes, and snippets.

@lgvalle
Created August 8, 2017 07:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lgvalle/3dcc4a0d588b2a27d015ba757d5b4e37 to your computer and use it in GitHub Desktop.
Save lgvalle/3dcc4a0d588b2a27d015ba757d5b4e37 to your computer and use it in GitHub Desktop.
function cleanUp(data) {
// Empty array to add cleaned up elements to
const items = []
// We are only interested in children of the 'channel' element
const channel = data.rss.channel
channel.item.forEach(element => {
item = {
title: element.title,
description: element.description,
date: element.pubDate,
creator: element['dc:creator'],
media: []
}
// Iterates through all the elements named '<media:content>' extracting the info we care about
element['media:content'].forEach(mediaContent => {
item.media.push({
url: mediaContent.$.url, // Parses media:content url attribute
credit: mediaContent['media:credit']._ // Parses media:credit tag content
})
})
items.push(item)
})
return items
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment