diff --git a/www/js/lib/zimArchive.js b/www/js/lib/zimArchive.js index 83e1a20b..9372fbd8 100644 --- a/www/js/lib/zimArchive.js +++ b/www/js/lib/zimArchive.js @@ -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); diff --git a/www/js/lib/zimDirEntry.js b/www/js/lib/zimDirEntry.js index 14685db7..974deb7e 100644 --- a/www/js/lib/zimDirEntry.js +++ b/www/js/lib/zimDirEntry.js @@ -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 */