зеркало из https://github.com/nextcloud/news.git
This commit is contained in:
Родитель
9aea5f3d3e
Коммит
217e219b28
|
@ -22,7 +22,7 @@ app.service('OPMLParser', function () {
|
|||
feeds: []
|
||||
};
|
||||
|
||||
// feed
|
||||
// feed
|
||||
} else {
|
||||
return {
|
||||
type: 'feed',
|
||||
|
@ -35,7 +35,7 @@ app.service('OPMLParser', function () {
|
|||
// there is only one level, so feeds in a folder in a folder should be
|
||||
// attached to the root folder
|
||||
var recursivelyParse = function (level, root, firstLevel) {
|
||||
for (var i=0; i<level.length; i+=1) {
|
||||
for (var i = 0; i < level.length; i += 1) {
|
||||
var outline = $(level[i]);
|
||||
|
||||
var entry = parseOutline(outline);
|
||||
|
@ -66,7 +66,26 @@ app.service('OPMLParser', function () {
|
|||
'folders': []
|
||||
};
|
||||
|
||||
return recursivelyParse(firstLevel, root, true);
|
||||
var parsedResult = recursivelyParse(firstLevel, root, true);
|
||||
|
||||
// merge folders with duplicate names
|
||||
var folders = {};
|
||||
parsedResult.folders.forEach(function (folder) {
|
||||
if (folders[folder.name] === undefined) {
|
||||
folders[folder.name] = folder;
|
||||
} else {
|
||||
folders[folder.name].feeds = folders[folder.name]
|
||||
.feeds.concat(folder.feeds);
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
'feeds': parsedResult.feeds,
|
||||
'folders': Object.keys(folders).map(function (key) {
|
||||
return folders[key];
|
||||
})
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
});
|
|
@ -40,6 +40,12 @@ describe('OPMLParser', function () {
|
|||
title='a-flat' \
|
||||
xmlUrl='http://a-flat.posterous.com/rss.xml'/> \
|
||||
</outline> \
|
||||
\<outline text='Nomadism'> \
|
||||
<outline \
|
||||
htmlUrl='http://google.com' \
|
||||
title='google' \
|
||||
xmlUrl='http://google.com/rss.xml'/> \
|
||||
</outline> \
|
||||
<outline title='Elezea' text='Elezee' \
|
||||
xmlUrl='http://feeds.feedburner.com/elezea'/> \
|
||||
</body> \
|
||||
|
@ -57,7 +63,7 @@ describe('OPMLParser', function () {
|
|||
expect(result.folders.length).toBe(2);
|
||||
expect(result.feeds.length).toBe(2);
|
||||
expect(result.folders[0].feeds.length).toBe(3);
|
||||
expect(result.folders[1].feeds.length).toBe(1);
|
||||
expect(result.folders[1].feeds.length).toBe(2);
|
||||
});
|
||||
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче