diff --git a/frontend/ui/widget/opdsbrowser.lua b/frontend/ui/widget/opdsbrowser.lua
index 312811f67..4fd142425 100644
--- a/frontend/ui/widget/opdsbrowser.lua
+++ b/frontend/ui/widget/opdsbrowser.lua
@@ -283,8 +283,12 @@ function OPDSBrowser:getCatalog(feed_url)
end
function OPDSBrowser:genItemTableFromURL(item_url, base_url)
- local item_table = {}
local catalog = self:getCatalog(item_url or base_url)
+ return self:genItemTableFromCatalog(catalog, item_url, base_url)
+end
+
+function OPDSBrowser:genItemTableFromCatalog(catalog, item_url, base_url)
+ local item_table = {}
if catalog then
local feed = catalog.feed or catalog
local function build_href(href)
@@ -332,7 +336,7 @@ function OPDSBrowser:genItemTableFromURL(item_url, base_url)
item.acquisitions = {}
if entry.link then
for i, link in ipairs(entry.link) do
- if link.type:find(self.catalog_type) and (not link.rel or link.rel == 'subsection') then
+ if link.type:find(self.catalog_type) and (not link.rel or link.rel == "subsection" or link.rel == "http://opds-spec.org/sort/popular" or link.rel == "http://opds-spec.org/sort/new") then
item.url = build_href(link.href)
end
if link.rel and link.rel:match(self.acquisition_rel) then
diff --git a/spec/unit/opdsbrowser_spec.lua b/spec/unit/opdsbrowser_spec.lua
new file mode 100644
index 000000000..19e08a97f
--- /dev/null
+++ b/spec/unit/opdsbrowser_spec.lua
@@ -0,0 +1,134 @@
+
+local navigation_sample = [[
+
+
+http://m.gutenberg.org/ebooks.opds/
+2014-05-17T12:04:49Z
+Project Gutenberg
+Free ebooks since 1971.
+
+Marcello Perathoner
+http://www.gutenberg.org
+webmaster@gutenberg.org
+
+http://m.gutenberg.org/pics/favicon.png
+
+
+
+
+25
+1
+
+2014-05-17T12:04:49Z
+http://m.gutenberg.org/ebooks/search.opds/?sort_order=downloads
+Popular
+Our most popular books.
+
+
+
+
+2014-05-17T12:04:49Z
+http://m.gutenberg.org/ebooks/search.opds/?sort_order=release_date
+Latest
+Our latest releases.
+
+
+
+
+2014-05-17T12:04:49Z
+http://m.gutenberg.org/ebooks/search.opds/?sort_order=random
+Random
+Random books.
+
+
+
+
+]]
+
+local popular_new_sample = [[
+
+
+ http://www.feedbooks.com/publicdomain/catalog.atom
+ Public Domain Books
+ 2014-11-30T17:54:01Z
+ http://assets3.feedbooks.net/images/favicon.ico?t=1417192326
+
+ Feedbooks
+ http://www.feedbooks.com
+ support@feedbooks.zendesk.com
+
+
+
+
+
+
+
+
+
+
+ Most Popular
+
+ 2014-11-30T17:54:01Z
+ http://www.feedbooks.com/books/top.atom
+ Based on last week's downloads
+
+
+ Recently Added
+
+ 2014-11-30T17:54:01Z
+ http://www.feedbooks.com/books/recent.atom
+ Find the latest books available
+
+
+ Fiction
+
+ 2014-11-30T17:54:01Z
+ http://www.feedbooks.com/books/categories.atom
+ Browse book by category
+
+
+ Non-Fiction
+
+ 2014-11-30T17:54:01Z
+ http://www.feedbooks.com/books/categories.atom
+ Browse book by category
+
+
+]]
+
+require("commonrequire")
+local OPDSParser = require("ui/opdsparser")
+local OPDSBrowser = require("ui/widget/opdsbrowser")
+local DEBUG = require("dbg")
+
+describe("OPDS browser module #nocov", function()
+ it("should generate URL on rel=subsection", function()
+ local catalog = OPDSParser:parse(navigation_sample)
+ local item_table = OPDSBrowser:genItemTableFromCatalog(catalog, "http://m.gutenberg.org/ebooks.opds/?format=opds")
+ --DEBUG(item_table)
+
+ assert.truthy(item_table)
+ assert.are.same(item_table[1].title, "Popular")
+ assert.are.same(item_table[1].url, "http://m.gutenberg.org/ebooks/search.opds/?sort_order=downloads")
+ end)
+ it("should generate URL on rel=popular and rel=new", function()
+ local catalog = OPDSParser:parse(popular_new_sample)
+ local item_table = OPDSBrowser:genItemTableFromCatalog(catalog, "http://www.feedbooks.com/publicdomain/catalog.atom")
+ --DEBUG(item_table)
+
+ assert.truthy(item_table)
+ assert.are.same(item_table[1].title, "Most Popular")
+ assert.are.same(item_table[1].url, "http://www.feedbooks.com/books/top.atom")
+ assert.are.same(item_table[2].title, "Recently Added")
+ assert.are.same(item_table[2].url, "http://www.feedbooks.com/books/recent.atom")
+ end)
+end)