mirror of https://github.com/kiwix/libkiwix.git
Merge pull request #446 from kiwix/libzim_random
Use the new libzim's getRandomEntry instead of implementing it ourselves.
This commit is contained in:
commit
89d7e68a39
|
@ -169,23 +169,11 @@ string Reader::getId() const
|
||||||
|
|
||||||
Entry Reader::getRandomPage() const
|
Entry Reader::getRandomPage() const
|
||||||
{
|
{
|
||||||
auto mainPagePath = zimArchive->getMainEntry().getPath();
|
try {
|
||||||
int watchdog = 42;
|
return zimArchive->getRandomEntry();
|
||||||
|
} catch(...) {
|
||||||
while (--watchdog){
|
|
||||||
auto idx = (zim::size_type)((double)rand() / ((double)RAND_MAX + 1)
|
|
||||||
* zimArchive->getEntryCount());
|
|
||||||
auto entry = zimArchive->getEntryByPath(idx);
|
|
||||||
|
|
||||||
if (entry.getPath()==mainPagePath) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
auto item = entry.getItem(true);
|
|
||||||
if (item.getMimetype() == "text/html") {
|
|
||||||
return entry;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw NoEntry();
|
throw NoEntry();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Entry Reader::getMainPage() const
|
Entry Reader::getMainPage() const
|
||||||
|
|
Loading…
Reference in New Issue