Adopt changes to getTitleOrUrl function from Kiwix JS

Former-commit-id: 99982d22209c3858c60a3e0ffe96ab60a88bee98 [formerly 7c6295f9a2643e4d8f6239e2059cd2de9b7e9d93]
Former-commit-id: 80f68e9b16d27e4db6dd51eeacacb0ffdaf3ce60
This commit is contained in:
Jaifroid 2019-05-03 10:03:07 +01:00
parent 92a8159709
commit b74228ce03
2 changed files with 4 additions and 9 deletions

View File

@ -190,13 +190,7 @@ define(['zimfile', 'zimDirEntry', 'util', 'utf8'],
if (dirEntry.namespace < "A") return 1;
if (dirEntry.namespace > "A") return -1;
// We should now be in namespace A
if (dirEntry.title) {
return prefix <= dirEntry.title ? -1 : 1;
} else {
// Some dirEntries (e.g. subtitles) have no title, but are still sorted in the A namespace,
// so, like libzim, we have to use the url as a comparator [kiwix-js #440 #443]
return prefix <= dirEntry.url ? -1 : 1;
}
return prefix <= dirEntry.getTitleOrUrl() ? -1 : 1;
});
}, true).then(function(firstIndex) {
var dirEntries = [];
@ -207,7 +201,7 @@ define(['zimfile', 'zimDirEntry', 'util', 'utf8'],
'nextStart': index
};
return that._file.dirEntryByTitleIndex(index).then(function(dirEntry) {
var title = dirEntry.title ? dirEntry.title : dirEntry.url;
var title = dirEntry.getTitleOrUrl();
if ((saveStartIndex === null || !title.indexOf(prefix)) && dirEntry.namespace === "A")
dirEntries.push(dirEntry);
return addDirEntries(index + 1);

View File

@ -108,7 +108,8 @@ define([], function() {
};
/**
* Defines a getter function that returns the URL if the title is empty
* Defines a function that returns the URL if the title is empty, as per the specification
* See https://wiki.openzim.org/wiki/ZIM_file_format#Directory_Entries
*
* @returns {String} The dirEntry's title or, if empty, the dirEntry's (unescaped) URL
*/