-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e4fb582
commit 4fff0de
Showing
4 changed files
with
28 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,22 @@ | ||
export default (data) => { | ||
const parser = new DOMParser(); | ||
const doc = parser.parseFromString(data, 'text/xml'); | ||
console.log(doc); | ||
const errorNode = doc.querySelector('parsererror'); | ||
if (errorNode) { | ||
throw new Error('parsererror'); | ||
} | ||
const feedTitle = doc.querySelector('title').textContent; | ||
const feedTitle = doc.querySelector('channel > title').textContent; | ||
console.log(feedTitle); | ||
const feedDescription = doc.querySelector('description').textContent; | ||
const feed = { title: feedTitle, description: feedDescription }; | ||
|
||
const posts = doc.querySelectorAll('items'); | ||
Array.from(posts).forEach((post) => { | ||
const postTitle = post.querySelector('title').textContent; | ||
const postDescription = post.querySelector('description').textContent; | ||
const postLink = post.querySelector('link').textContent; | ||
return { title: postTitle, description: postDescription, link: postLink }; | ||
console.log(feed); | ||
const items = doc.querySelectorAll('items'); | ||
const posts = Array.from(items).map((post) => { | ||
const title = post.querySelector('title').textContent; | ||
const description = post.querySelector('description').textContent; | ||
return { title, description }; | ||
}); | ||
console.log(feed, posts); | ||
return { feed, posts }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters