mirror of https://github.com/kiwix/libkiwix.git
+ better default page loading
This commit is contained in:
parent
fb1d0893e3
commit
d0d08c4f96
|
@ -216,14 +216,7 @@ namespace kiwix {
|
|||
return url;
|
||||
}
|
||||
|
||||
/* Get a content from a zim file */
|
||||
bool Reader::getContentByUrl(const string &urlStr, string &content, unsigned int &contentLength, string &contentType) {
|
||||
bool retVal = false;
|
||||
content="";
|
||||
contentType="";
|
||||
contentLength = 0;
|
||||
|
||||
if (this->zimFileHandler != NULL) {
|
||||
bool Reader::parseUrl(const string &urlStr, char *ns, string &titleStr) {
|
||||
const char *url = urlStr.c_str();
|
||||
|
||||
/* Offset to visit the url */
|
||||
|
@ -234,14 +227,10 @@ namespace kiwix {
|
|||
while ((offset < urlLength) && (url[offset] == '/')) offset++;
|
||||
|
||||
/* Get namespace */
|
||||
char ns[1024];
|
||||
unsigned int nsOffset = 0;
|
||||
while ((offset < urlLength) && (url[offset] != '/')) {
|
||||
ns[nsOffset] = url[offset];
|
||||
*ns= url[offset];
|
||||
offset++;
|
||||
nsOffset++;
|
||||
}
|
||||
ns[nsOffset] = 0;
|
||||
|
||||
/* Ignore the '/' */
|
||||
while ((offset < urlLength) && (url[offset] == '/')) offset++;
|
||||
|
@ -257,20 +246,33 @@ namespace kiwix {
|
|||
title[titleOffset] = 0;
|
||||
|
||||
/* unescape url */
|
||||
string titleStr = string(title);
|
||||
titleStr = string(title);
|
||||
unescapeUrl(titleStr);
|
||||
|
||||
/* Main page */
|
||||
if (titleStr == "" && strcmp(ns, "") == 0) {
|
||||
if (zimFileHandler->getFileheader().hasMainPage()) {
|
||||
zim::Article article = zimFileHandler->getArticle(zimFileHandler->getFileheader().getMainPage());
|
||||
ns[0] = article.getNamespace();
|
||||
titleStr = article.getUrl();
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Get a content from a zim file */
|
||||
bool Reader::getContentByUrl(const string &urlStr, string &content, unsigned int &contentLength, string &contentType) {
|
||||
bool retVal = false;
|
||||
content="";
|
||||
contentType="";
|
||||
contentLength = 0;
|
||||
|
||||
if (this->zimFileHandler != NULL) {
|
||||
|
||||
/* Parse the url */
|
||||
char ns = 0;
|
||||
string titleStr;
|
||||
this->parseUrl(urlStr, &ns, titleStr);
|
||||
|
||||
/* Main page */
|
||||
if (titleStr.empty() && ns == 0) {
|
||||
this->parseUrl(this->getMainPageUrl(), &ns, titleStr);
|
||||
}
|
||||
|
||||
/* Extract the content from the zim file */
|
||||
std::pair<bool, zim::File::const_iterator> resultPair = zimFileHandler->findx(ns[0], titleStr);
|
||||
std::pair<bool, zim::File::const_iterator> resultPair = zimFileHandler->findx(ns, titleStr);
|
||||
|
||||
/* Test if the article was found */
|
||||
if (resultPair.first == true) {
|
||||
|
|
|
@ -59,6 +59,7 @@ namespace kiwix {
|
|||
bool getNextSuggestion(string &title);
|
||||
bool canCheckIntegrity();
|
||||
bool isCorrupted();
|
||||
bool parseUrl(const string &urlStr, char *ns, string &titleStr);
|
||||
|
||||
protected:
|
||||
zim::File* zimFileHandler;
|
||||
|
|
Loading…
Reference in New Issue