mirror of
https://github.com/kiwix/kiwix-tools.git
synced 2026-01-13 16:37:44 -05:00
Compare commits
35 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b1d2a1378b | ||
|
|
df7d44128c | ||
|
|
ee5333bb91 | ||
|
|
871d8f4a51 | ||
|
|
9280d519f5 | ||
|
|
540fcd3be9 | ||
|
|
ad7238b0c9 | ||
|
|
b5c91417ff | ||
|
|
b638df81fa | ||
|
|
58f0a716a6 | ||
|
|
a2324b5e8b | ||
|
|
c2ac40d4f5 | ||
|
|
4534b51f5e | ||
|
|
0364951f75 | ||
|
|
a2627e81c4 | ||
|
|
cd72a2d73c | ||
|
|
fa3f33d3c7 | ||
|
|
a210cb3a4b | ||
|
|
63cb47247b | ||
|
|
3220ee1276 | ||
|
|
4a1b9cbfa9 | ||
|
|
f2b5904221 | ||
|
|
f44722fbbc | ||
|
|
0cfcc59437 | ||
|
|
7776eafbfc | ||
|
|
5989146931 | ||
|
|
ea088b21a4 | ||
|
|
558a0375b0 | ||
|
|
5f0a05e8d8 | ||
|
|
4b9dc39c49 | ||
|
|
08f2373360 | ||
|
|
82fb6bc4d0 | ||
|
|
17eceeff5b | ||
|
|
aef20d6c96 | ||
|
|
4e3ff03059 |
12
.clang-format
Normal file
12
.clang-format
Normal file
@@ -0,0 +1,12 @@
|
||||
BasedOnStyle: Google
|
||||
BinPackArguments: false
|
||||
BinPackParameters: false
|
||||
BreakBeforeBinaryOperators: All
|
||||
BreakBeforeBraces: Linux
|
||||
DerivePointerAlignment: false
|
||||
SpacesInContainerLiterals: false
|
||||
Standard: Cpp11
|
||||
|
||||
AllowShortFunctionsOnASingleLine: Inline
|
||||
AllowShortIfStatementsOnASingleLine: false
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
25
Changelog
25
Changelog
@@ -1,10 +1,33 @@
|
||||
kiwix-tools 0.3.0
|
||||
=================
|
||||
|
||||
* Move to C++11
|
||||
|
||||
kiwix-serve
|
||||
-----------
|
||||
|
||||
* Add a global taskbar in the welcome page to search in all zims (#49)
|
||||
* Serve the taskbar as css file instead of including it in the html (#68):
|
||||
* Better client caching
|
||||
* The html encoding is now in the first 1024 bytes and firefox correctly
|
||||
detect the encoding
|
||||
* Make kiwix-server multi-threaded (#82)
|
||||
* Correctly return 404 instead of crashing when request inexistant skin file
|
||||
(#83)
|
||||
* Correctly respond to bytes-range requests.(#84)
|
||||
* Directly respond to first request for a url instead of refusing the first
|
||||
connexion
|
||||
* Add support to relative url location. (#86)
|
||||
* Remove caching (on client side) for the welcome page. (#86)
|
||||
|
||||
|
||||
kiwix-tools 0.2.0
|
||||
=================
|
||||
|
||||
* Remove indexer tools
|
||||
|
||||
kiwix-serve
|
||||
----------
|
||||
-----------
|
||||
|
||||
* Correctly fix the deflate data we send over http. (#15)
|
||||
* Update in the taskbar (or topbar):
|
||||
|
||||
15
format_code.sh
Executable file
15
format_code.sh
Executable file
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
files=(
|
||||
"src/installer/kiwix-install.cpp"
|
||||
"src/searcher/kiwix-search.cpp"
|
||||
"src/reader/kiwix-read.cpp"
|
||||
"src/manager/kiwix-manage.cpp"
|
||||
"src/server/kiwix-serve.cpp"
|
||||
)
|
||||
|
||||
for i in "${files[@]}"
|
||||
do
|
||||
echo $i
|
||||
clang-format -i -style=file $i
|
||||
done
|
||||
@@ -1,6 +1,7 @@
|
||||
project('kiwix-tools', 'cpp',
|
||||
version : '0.2.0',
|
||||
license : 'GPL')
|
||||
version : '0.3.0',
|
||||
license : 'GPL',
|
||||
default_options: ['c_std=c11', 'cpp_std=c++11'])
|
||||
|
||||
compiler = meson.get_compiler('cpp')
|
||||
|
||||
@@ -10,7 +11,7 @@ if static_linkage
|
||||
endif
|
||||
|
||||
thread_dep = dependency('threads')
|
||||
kiwixlib_dep = dependency('kiwix', static:static_linkage)
|
||||
kiwixlib_dep = dependency('kiwix', version:'>=1.0.0', static:static_linkage)
|
||||
microhttpd_dep = dependency('libmicrohttpd', static:static_linkage)
|
||||
z_dep = dependency('zlib', static:static_linkage)
|
||||
|
||||
|
||||
@@ -19,21 +19,23 @@
|
||||
|
||||
#include <getopt.h>
|
||||
#include <kiwix/common/pathTools.h>
|
||||
#include <kiwix/reader.h>
|
||||
#include <kiwix/manager.h>
|
||||
#include <kiwix/reader.h>
|
||||
|
||||
enum supportedAction { NONE, ADDCONTENT };
|
||||
|
||||
void usage() {
|
||||
cout << "Usage: kiwix-install [--verbose] addcontent ZIM_PATH KIWIX_PATH" << endl;
|
||||
exit(1);
|
||||
void usage()
|
||||
{
|
||||
cout << "Usage: kiwix-install [--verbose] addcontent ZIM_PATH KIWIX_PATH"
|
||||
<< endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
/* Init the variables */
|
||||
const char *contentPath = NULL;
|
||||
const char *kiwixPath = NULL;
|
||||
const char* contentPath = NULL;
|
||||
const char* kiwixPath = NULL;
|
||||
supportedAction action = NONE;
|
||||
bool verboseFlag = false;
|
||||
int option_index = 0;
|
||||
@@ -41,36 +43,33 @@ int main(int argc, char **argv) {
|
||||
|
||||
/* Argument parsing */
|
||||
while (42) {
|
||||
|
||||
static struct option long_options[] = {
|
||||
{"verbose", no_argument, 0, 'v'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
static struct option long_options[]
|
||||
= {{"verbose", no_argument, 0, 'v'}, {0, 0, 0, 0}};
|
||||
|
||||
if (c != -1) {
|
||||
c = getopt_long(argc, argv, "vi", long_options, &option_index);
|
||||
|
||||
switch (c) {
|
||||
case 'v':
|
||||
verboseFlag = true;
|
||||
break;
|
||||
case 'v':
|
||||
verboseFlag = true;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (optind < argc) {
|
||||
if (action == NONE) {
|
||||
string actionString = argv[optind++];
|
||||
if (actionString == "addcontent" || actionString == "ADDCONTENT") {
|
||||
action = ADDCONTENT;
|
||||
}
|
||||
} else if (contentPath == NULL) {
|
||||
contentPath = argv[optind++];
|
||||
} else if (kiwixPath == NULL) {
|
||||
kiwixPath = argv[optind++];
|
||||
} else {
|
||||
usage();
|
||||
}
|
||||
if (action == NONE) {
|
||||
string actionString = argv[optind++];
|
||||
if (actionString == "addcontent" || actionString == "ADDCONTENT") {
|
||||
action = ADDCONTENT;
|
||||
}
|
||||
} else if (contentPath == NULL) {
|
||||
contentPath = argv[optind++];
|
||||
} else if (kiwixPath == NULL) {
|
||||
kiwixPath = argv[optind++];
|
||||
} else {
|
||||
usage();
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -82,38 +81,48 @@ int main(int argc, char **argv) {
|
||||
|
||||
/* Make the action */
|
||||
if (action == ADDCONTENT) {
|
||||
|
||||
/* Check if the content path exists and is readable */
|
||||
if (verboseFlag) { std::cout << "Check if the ZIM file exists..." << std::endl; }
|
||||
if (verboseFlag) {
|
||||
std::cout << "Check if the ZIM file exists..." << std::endl;
|
||||
}
|
||||
if (!fileExists(contentPath)) {
|
||||
cerr << "The content path '" << contentPath << "' does not exist or is not readable." << endl;
|
||||
cerr << "The content path '" << contentPath
|
||||
<< "' does not exist or is not readable." << endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Check if this is a ZIM file */
|
||||
try {
|
||||
if (verboseFlag) { std::cout << "Check if the ZIM file is valid..." << std::endl; }
|
||||
kiwix::Reader *reader = new kiwix::Reader(contentPath);
|
||||
if (verboseFlag) {
|
||||
std::cout << "Check if the ZIM file is valid..." << std::endl;
|
||||
}
|
||||
kiwix::Reader* reader = new kiwix::Reader(contentPath);
|
||||
delete reader;
|
||||
} catch (exception &e) {
|
||||
cerr << "The content available at '" << contentPath << "' is not a ZIM file." << endl;
|
||||
} catch (exception& e) {
|
||||
cerr << "The content available at '" << contentPath
|
||||
<< "' is not a ZIM file." << endl;
|
||||
exit(1);
|
||||
}
|
||||
string contentFilename = getLastPathElement(contentPath);
|
||||
|
||||
/* Check if kiwixPath/kiwix/kiwix.exe exists */
|
||||
if (verboseFlag) { std::cout << "Check if the Kiwix path is valid..." << std::endl; }
|
||||
if (verboseFlag) {
|
||||
std::cout << "Check if the Kiwix path is valid..." << std::endl;
|
||||
}
|
||||
string kiwixBinaryPath = computeAbsolutePath(kiwixPath, "kiwix/kiwix.exe");
|
||||
if (!fileExists(kiwixBinaryPath)) {
|
||||
kiwixBinaryPath = computeAbsolutePath(kiwixPath, "kiwix/kiwix");
|
||||
if (!fileExists(kiwixBinaryPath)) {
|
||||
cerr << "Unable to find the Kiwix binary at '" << kiwixBinaryPath << "[.exe]'." << endl;
|
||||
exit(1);
|
||||
cerr << "Unable to find the Kiwix binary at '" << kiwixBinaryPath
|
||||
<< "[.exe]'." << endl;
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
/* Check if the directory "data" structure exists */
|
||||
if (verboseFlag) { std::cout << "Check the target data directory structure..." << std::endl; }
|
||||
if (verboseFlag) {
|
||||
std::cout << "Check the target data directory structure..." << std::endl;
|
||||
}
|
||||
string dataPath = computeAbsolutePath(kiwixPath, "data/");
|
||||
if (!fileExists(dataPath)) {
|
||||
makeDirectory(dataPath);
|
||||
@@ -132,22 +141,31 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
|
||||
/* Copy the file to the data/content directory */
|
||||
if (verboseFlag) { std::cout << "Copy ZIM file to the target directory..." << std::endl; }
|
||||
string newContentPath = computeAbsolutePath(dataContentPath, contentFilename);
|
||||
if (!fileExists(newContentPath) || getFileSize(contentPath) != getFileSize(newContentPath)) {
|
||||
if (verboseFlag) {
|
||||
std::cout << "Copy ZIM file to the target directory..." << std::endl;
|
||||
}
|
||||
string newContentPath
|
||||
= computeAbsolutePath(dataContentPath, contentFilename);
|
||||
if (!fileExists(newContentPath)
|
||||
|| getFileSize(contentPath) != getFileSize(newContentPath)) {
|
||||
copyFile(contentPath, newContentPath);
|
||||
}
|
||||
|
||||
/* Add the file to the library.xml */
|
||||
if (verboseFlag) { std::cout << "Create the library XML file..." << std::endl; }
|
||||
if (verboseFlag) {
|
||||
std::cout << "Create the library XML file..." << std::endl;
|
||||
}
|
||||
kiwix::Manager libraryManager;
|
||||
string libraryPath = computeAbsolutePath(dataLibraryPath, contentFilename + ".xml");
|
||||
string bookId = libraryManager.addBookFromPathAndGetId(newContentPath, "../content/" + contentFilename, "", false);
|
||||
string libraryPath
|
||||
= computeAbsolutePath(dataLibraryPath, contentFilename + ".xml");
|
||||
string bookId = libraryManager.addBookFromPathAndGetId(
|
||||
newContentPath, "../content/" + contentFilename, "", false);
|
||||
if (!bookId.empty()) {
|
||||
libraryManager.setCurrentBookId(bookId);
|
||||
libraryManager.writeFile(libraryPath);
|
||||
} else {
|
||||
cerr << "Unable to build or save library file '" << libraryPath << "'" << endl;
|
||||
cerr << "Unable to build or save library file '" << libraryPath << "'"
|
||||
<< endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,47 +21,54 @@
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <getopt.h>
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include <kiwix/common/pathTools.h>
|
||||
#include <kiwix/manager.h>
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
enum supportedAction { NONE, ADD, SHOW, REMOVE };
|
||||
|
||||
|
||||
void show(kiwix::Library library) {
|
||||
std::vector<kiwix::Book>::iterator itr;
|
||||
unsigned int inc = 1;
|
||||
for ( itr = library.books.begin(); itr != library.books.end(); ++itr ) {
|
||||
std::cout << "#" << inc++
|
||||
<< std::endl << "id:\t\t" << itr->id
|
||||
<< std::endl << "path:\t\t" << itr->path
|
||||
<< std::endl << "indexpath:\t" << itr->indexPath
|
||||
<< std::endl << "url:\t\t" << itr->url
|
||||
<< std::endl << "title:\t\t" << itr->title
|
||||
<< std::endl << "name:\t\t" << itr->name
|
||||
<< std::endl << "tags:\t\t" << itr->tags
|
||||
<< std::endl << "description:\t" << itr->description
|
||||
<< std::endl << "creator:\t" << itr->creator
|
||||
<< std::endl << "date:\t\t" << itr->date
|
||||
<< std::endl << "articleCount:\t" << itr->articleCount
|
||||
<< std::endl << "mediaCount:\t" << itr->mediaCount
|
||||
<< std::endl << "size:\t\t" << itr->size << " KB"
|
||||
<< std::endl << std::endl;
|
||||
}
|
||||
void show(kiwix::Library library)
|
||||
{
|
||||
std::vector<kiwix::Book>::iterator itr;
|
||||
unsigned int inc = 1;
|
||||
for (itr = library.books.begin(); itr != library.books.end(); ++itr) {
|
||||
std::cout << "#" << inc++ << std::endl
|
||||
<< "id:\t\t" << itr->id << std::endl
|
||||
<< "path:\t\t" << itr->path << std::endl
|
||||
<< "indexpath:\t" << itr->indexPath << std::endl
|
||||
<< "url:\t\t" << itr->url << std::endl
|
||||
<< "title:\t\t" << itr->title << std::endl
|
||||
<< "name:\t\t" << itr->name << std::endl
|
||||
<< "tags:\t\t" << itr->tags << std::endl
|
||||
<< "description:\t" << itr->description << std::endl
|
||||
<< "creator:\t" << itr->creator << std::endl
|
||||
<< "date:\t\t" << itr->date << std::endl
|
||||
<< "articleCount:\t" << itr->articleCount << std::endl
|
||||
<< "mediaCount:\t" << itr->mediaCount << std::endl
|
||||
<< "size:\t\t" << itr->size << " KB" << std::endl
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void usage() {
|
||||
cerr << "Usage:" << endl;
|
||||
cerr << "\tkiwix-manage LIBRARY_PATH add ZIM_PATH [--zimPathToSave=../content/foobar.zim] [--current] [--indexBackend=xapian] [--indexPath=FULLTEXT_IDX_PATH] [--url=http://...metalink]" << endl;
|
||||
cerr << "\tkiwix-manage LIBRARY_PATH show [CONTENTID1] [CONTENTID2] ... (show everything if no param.)" << endl;
|
||||
cerr << "\tkiwix-manage LIBRARY_PATH remove CONTENTID1 [CONTENTID2]" << endl;
|
||||
void usage()
|
||||
{
|
||||
cerr << "Usage:" << endl;
|
||||
cerr << "\tkiwix-manage LIBRARY_PATH add ZIM_PATH "
|
||||
"[--zimPathToSave=../content/foobar.zim] [--current] "
|
||||
"[--indexBackend=xapian] [--indexPath=FULLTEXT_IDX_PATH] "
|
||||
"[--url=http://...metalink]"
|
||||
<< endl;
|
||||
cerr << "\tkiwix-manage LIBRARY_PATH show [CONTENTID1] [CONTENTID2] ... "
|
||||
"(show everything if no param.)"
|
||||
<< endl;
|
||||
cerr << "\tkiwix-manage LIBRARY_PATH remove CONTENTID1 [CONTENTID2]" << endl;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
string libraryPath = "";
|
||||
supportedAction action = NONE;
|
||||
string zimPath = "";
|
||||
@@ -89,9 +96,9 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
|
||||
/* Try to read the file */
|
||||
libraryPath = isRelativePath(libraryPath) ?
|
||||
computeAbsolutePath(getCurrentDirectory(), libraryPath) :
|
||||
libraryPath;
|
||||
libraryPath = isRelativePath(libraryPath)
|
||||
? computeAbsolutePath(getCurrentDirectory(), libraryPath)
|
||||
: libraryPath;
|
||||
libraryManager.readFile(libraryPath, false);
|
||||
|
||||
/* SHOW */
|
||||
@@ -103,81 +110,78 @@ int main(int argc, char **argv) {
|
||||
string indexPath;
|
||||
kiwix::supportedIndexType indexBackend = kiwix::XAPIAN;
|
||||
string url;
|
||||
string origID="";
|
||||
string origID = "";
|
||||
bool setCurrent = false;
|
||||
|
||||
if (argc>3) {
|
||||
if (argc > 3) {
|
||||
zimPath = argv[3];
|
||||
}
|
||||
|
||||
/* Options parsing */
|
||||
optind = 2;
|
||||
while (42) {
|
||||
static struct option long_options[]
|
||||
= {{"url", required_argument, 0, 'u'},
|
||||
{"origId", required_argument, 0, 'o'},
|
||||
{"indexPath", required_argument, 0, 'i'},
|
||||
{"indexBackend", required_argument, 0, 'b'},
|
||||
{"zimPathToSave", required_argument, 0, 'z'},
|
||||
{"current", no_argument, 0, 'c'},
|
||||
{0, 0, 0, 0}};
|
||||
|
||||
static struct option long_options[] = {
|
||||
{"url", required_argument, 0, 'u'},
|
||||
{"origId", required_argument, 0, 'o'},
|
||||
{"indexPath", required_argument, 0, 'i'},
|
||||
{"indexBackend", required_argument, 0, 'b'},
|
||||
{"zimPathToSave", required_argument, 0, 'z'},
|
||||
{"current", no_argument, 0, 'c'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
c = getopt_long(argc, argv, "cz:u:i:b:", long_options, &option_index);
|
||||
|
||||
|
||||
if (c != -1) {
|
||||
switch (c) {
|
||||
case 'u':
|
||||
url = optarg;
|
||||
break;
|
||||
|
||||
switch (c) {
|
||||
case 'u':
|
||||
url = optarg;
|
||||
break;
|
||||
case 'o':
|
||||
origID = optarg;
|
||||
break;
|
||||
|
||||
case 'o':
|
||||
origID = optarg;
|
||||
break;
|
||||
case 'c':
|
||||
setCurrent = true;
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
setCurrent = true;
|
||||
break;
|
||||
case 'i':
|
||||
indexPath = optarg;
|
||||
break;
|
||||
|
||||
case 'i':
|
||||
indexPath = optarg;
|
||||
break;
|
||||
case 'b':
|
||||
if (!strcmp(optarg, "xapian")) {
|
||||
indexBackend = kiwix::XAPIAN;
|
||||
} else {
|
||||
usage();
|
||||
}
|
||||
break;
|
||||
|
||||
case 'b':
|
||||
if (!strcmp(optarg, "xapian")) {
|
||||
indexBackend = kiwix::XAPIAN;
|
||||
} else {
|
||||
usage();
|
||||
}
|
||||
break;
|
||||
|
||||
case 'z':
|
||||
zimPathToSave = optarg;
|
||||
break;
|
||||
|
||||
}
|
||||
case 'z':
|
||||
zimPathToSave = optarg;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!zimPath.empty()) {
|
||||
zimPathToSave = zimPathToSave == "." ? zimPath : zimPathToSave;
|
||||
string bookId = libraryManager.addBookFromPathAndGetId(zimPath, zimPathToSave, url, false);
|
||||
string bookId = libraryManager.addBookFromPathAndGetId(
|
||||
zimPath, zimPathToSave, url, false);
|
||||
|
||||
if (!bookId.empty()) {
|
||||
if (setCurrent)
|
||||
libraryManager.setCurrentBookId(bookId);
|
||||
|
||||
if (setCurrent)
|
||||
libraryManager.setCurrentBookId(bookId);
|
||||
|
||||
/* Save the index infos if necessary */
|
||||
if (!indexPath.empty())
|
||||
libraryManager.setBookIndex(bookId, indexPath, indexBackend);
|
||||
/* Save the index infos if necessary */
|
||||
if (!indexPath.empty())
|
||||
libraryManager.setBookIndex(bookId, indexPath, indexBackend);
|
||||
|
||||
} else {
|
||||
cerr << "Unable to build or save library file '" << libraryPath << "'" << endl;
|
||||
cerr << "Unable to build or save library file '" << libraryPath << "'"
|
||||
<< endl;
|
||||
}
|
||||
} else {
|
||||
std::cerr << "Invalid zim file path" << std::endl;
|
||||
@@ -187,7 +191,7 @@ int main(int argc, char **argv) {
|
||||
unsigned int bookIndex = 0;
|
||||
const unsigned int totalBookCount = libraryManager.getBookCount(true, true);
|
||||
|
||||
if (argc>3) {
|
||||
if (argc > 3) {
|
||||
bookIndex = atoi(argv[3]);
|
||||
}
|
||||
|
||||
@@ -195,9 +199,13 @@ int main(int argc, char **argv) {
|
||||
libraryManager.removeBookByIndex(bookIndex - 1);
|
||||
} else {
|
||||
if (totalBookCount > 0) {
|
||||
std::cerr << "Invalid book index number. Please give a number between 1 and " << totalBookCount << std::endl;
|
||||
std::cerr
|
||||
<< "Invalid book index number. Please give a number between 1 and "
|
||||
<< totalBookCount << std::endl;
|
||||
} else {
|
||||
std::cerr << "Invalid book index number. Library is empty, no book to delete." << std::endl;
|
||||
std::cerr
|
||||
<< "Invalid book index number. Library is empty, no book to delete."
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,59 +18,53 @@
|
||||
*/
|
||||
|
||||
#include <getopt.h>
|
||||
#include <unistd.h>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <kiwix/common/tree.h>
|
||||
#include <kiwix/reader.h>
|
||||
#include <unistd.h>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
void usage() {
|
||||
cout << "Usage: kiwix-read --suggest=<PATTERN> ZIM_FILE_PATH" << endl;
|
||||
exit(1);
|
||||
void usage()
|
||||
{
|
||||
cout << "Usage: kiwix-read --suggest=<PATTERN> ZIM_FILE_PATH" << endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void updateSuggestionTree(tree< pair<string, unsigned> > &suggestionTree, string suggestion) {
|
||||
return;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
/* Init the variables */
|
||||
const char *filePath = NULL;
|
||||
const char *pattern = NULL;
|
||||
const char* filePath = NULL;
|
||||
const char* pattern = NULL;
|
||||
int option_index = 0;
|
||||
int c = 0;
|
||||
|
||||
kiwix::Reader *reader = NULL;
|
||||
kiwix::Reader* reader = NULL;
|
||||
|
||||
/* Argument parsing */
|
||||
while (42) {
|
||||
static struct option long_options[]
|
||||
= {{"verbose", no_argument, 0, 'v'},
|
||||
{"suggest", required_argument, 0, 's'},
|
||||
{0, 0, 0, 0}};
|
||||
|
||||
static struct option long_options[] = {
|
||||
{"verbose", no_argument, 0, 'v'},
|
||||
{"suggest", required_argument, 0, 's'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
if (c != -1) {
|
||||
c = getopt_long(argc, argv, "vs:", long_options, &option_index);
|
||||
|
||||
switch (c) {
|
||||
case 'v':
|
||||
break;
|
||||
case 's':
|
||||
pattern = optarg;
|
||||
break;
|
||||
case 'v':
|
||||
break;
|
||||
case 's':
|
||||
pattern = optarg;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (optind < argc) {
|
||||
if (filePath == NULL) {
|
||||
filePath = argv[optind++];
|
||||
} else {
|
||||
usage();
|
||||
}
|
||||
if (filePath == NULL) {
|
||||
filePath = argv[optind++];
|
||||
} else {
|
||||
usage();
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -90,25 +84,23 @@ int main(int argc, char **argv) {
|
||||
string contentType;
|
||||
unsigned int contentLength = 0;
|
||||
string suggestion;
|
||||
|
||||
|
||||
if (pattern != NULL) {
|
||||
std::cout << "Searching suggestions for: " << pattern << std::endl;
|
||||
|
||||
reader->searchSuggestionsSmart(pattern, 10);
|
||||
while (reader->getNextSuggestion(suggestion)) {
|
||||
std::cout << suggestion << std::endl;
|
||||
std::cout << suggestion << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
if (reader->getContentByUrl(mainPageUrl, content, contentLength, contentType)) {
|
||||
if (reader->getContentByUrl(mainPageUrl, content, contentLength,
|
||||
contentType)) {
|
||||
cout << content << endl;
|
||||
}
|
||||
*/
|
||||
|
||||
// tree< pair<string, unsigned> > tree;
|
||||
//updateSuggestionTree(tree, string(suggestion));
|
||||
|
||||
delete reader;
|
||||
} else {
|
||||
cerr << "Unable instanciate the Kiwix reader." << endl;
|
||||
|
||||
@@ -18,57 +18,56 @@
|
||||
*/
|
||||
|
||||
#include <getopt.h>
|
||||
#include <unistd.h>
|
||||
#include <kiwix/reader.h>
|
||||
#include <kiwix/searcher.h>
|
||||
#include <unistd.h>
|
||||
|
||||
void usage() {
|
||||
cout << "Usage: kiwix-search [--verbose|-v] ZIM_PATH SEARCH" << endl;
|
||||
exit(1);
|
||||
void usage()
|
||||
{
|
||||
cout << "Usage: kiwix-search [--verbose|-v] ZIM_PATH SEARCH" << endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
/* Init the variables */
|
||||
//const char *indexPath = "/home/itamar/.www.kiwix.org/kiwix/43k0i1j4.default/6d2e587b-d586-dc6a-dc6a-e4ef035a1495d15c.index";
|
||||
//const char *indexPath = "/home/itamar/testindex";
|
||||
const char *zimPath = NULL;
|
||||
const char *search = NULL;
|
||||
// const char *indexPath =
|
||||
// "/home/itamar/.www.kiwix.org/kiwix/43k0i1j4.default/6d2e587b-d586-dc6a-dc6a-e4ef035a1495d15c.index";
|
||||
// const char *indexPath = "/home/itamar/testindex";
|
||||
const char* zimPath = NULL;
|
||||
const char* search = NULL;
|
||||
bool verboseFlag = false;
|
||||
int option_index = 0;
|
||||
int c = 0;
|
||||
|
||||
kiwix::Searcher *searcher = NULL;
|
||||
kiwix::Reader *reader = NULL;
|
||||
kiwix::Searcher* searcher = NULL;
|
||||
kiwix::Reader* reader = NULL;
|
||||
|
||||
/* Argument parsing */
|
||||
while (42) {
|
||||
|
||||
static struct option long_options[] = {
|
||||
{"verbose", no_argument, 0, 'v'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
static struct option long_options[]
|
||||
= {{"verbose", no_argument, 0, 'v'}, {0, 0, 0, 0}};
|
||||
|
||||
if (c != -1) {
|
||||
c = getopt_long(argc, argv, "vb:", long_options, &option_index);
|
||||
|
||||
switch (c) {
|
||||
case 'v':
|
||||
verboseFlag = true;
|
||||
break;
|
||||
case 'v':
|
||||
verboseFlag = true;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (optind < argc) {
|
||||
if (zimPath == NULL) {
|
||||
zimPath = argv[optind++];
|
||||
} else if (search == NULL) {
|
||||
search = argv[optind++];
|
||||
} else {
|
||||
cout << zimPath << endl;
|
||||
usage();
|
||||
}
|
||||
if (zimPath == NULL) {
|
||||
zimPath = argv[optind++];
|
||||
} else if (search == NULL) {
|
||||
search = argv[optind++];
|
||||
} else {
|
||||
cout << zimPath << endl;
|
||||
usage();
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -80,20 +79,22 @@ int main(int argc, char **argv) {
|
||||
|
||||
/* Try to prepare the indexing */
|
||||
try {
|
||||
reader = new kiwix::Reader(zimPath);
|
||||
reader = new kiwix::Reader(zimPath);
|
||||
} catch (...) {
|
||||
/* Cannot open the zimPath, maybe it is a plain old xapian database directory */
|
||||
/* Cannot open the zimPath, maybe it is a plain old xapian database
|
||||
* directory */
|
||||
}
|
||||
|
||||
if ( reader ) {
|
||||
searcher = new kiwix::Searcher("", reader);
|
||||
if (reader) {
|
||||
searcher = new kiwix::Searcher();
|
||||
searcher->add_reader(reader, "");
|
||||
} else {
|
||||
try {
|
||||
searcher = new kiwix::Searcher(zimPath, NULL);
|
||||
} catch (...) {
|
||||
cerr << "Unable to search through zim '" << zimPath << "'." << endl;
|
||||
exit(1);
|
||||
}
|
||||
try {
|
||||
searcher = new kiwix::Searcher(zimPath, NULL, "");
|
||||
} catch (...) {
|
||||
cerr << "Unable to search through zim '" << zimPath << "'." << endl;
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
/* Start the indexing */
|
||||
@@ -101,7 +102,7 @@ int main(int argc, char **argv) {
|
||||
string searchString(search);
|
||||
searcher->search(searchString, 0, 10);
|
||||
kiwix::Result* p_result;
|
||||
while ( (p_result = searcher->getNextResult()) ) {
|
||||
while ((p_result = searcher->getNextResult())) {
|
||||
cout << p_result->get_title() << endl;
|
||||
delete p_result;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,4 @@
|
||||
|
||||
res_compiler = find_program('compile_resources.py')
|
||||
res_compiler = find_program('kiwix-compile-resources', 'compile_resources.py')
|
||||
|
||||
subdir('server')
|
||||
|
||||
13
static/server/global_taskbar.html.part
Normal file
13
static/server/global_taskbar.html.part
Normal file
@@ -0,0 +1,13 @@
|
||||
<span class="kiwix">
|
||||
<span id="kiwixtoolbar" class="ui-widget-header">
|
||||
<div class="kiwix_centered">
|
||||
<div class="kiwix_searchform">
|
||||
<form class="kiwixsearch" method="GET" action="__ROOT_LOCATION__/search" id="kiwixsearchform">
|
||||
<input autocomplete="off" class="ui-autocomplete-input" id="kiwixsearchbox" name="pattern" type="text">
|
||||
<input type="submit" value="Search">
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</span>
|
||||
</span>
|
||||
<div style="display: block; height: 5em;"></div>
|
||||
@@ -3,10 +3,10 @@
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>Welcome to Kiwix Server</title>
|
||||
<script type="text/javascript" src="/skin/jquery-ui/external/jquery/jquery.js"></script>
|
||||
<script type="text/javascript" src="/skin/jquery-ui/jquery-ui.min.js"></script>
|
||||
<link type="text/css" href="/skin/jquery-ui/jquery-ui.min.css" rel="Stylesheet" />
|
||||
<link type="text/css" href="/skin/jquery-ui/jquery-ui.theme.min.css" rel="Stylesheet" />
|
||||
<script type="text/javascript" src="__ROOT_LOCATION__/skin/jquery-ui/external/jquery/jquery.js"></script>
|
||||
<script type="text/javascript" src="__ROOT_LOCATION__/skin/jquery-ui/jquery-ui.min.js"></script>
|
||||
<link type="text/css" href="__ROOT_LOCATION__/skin/jquery-ui/jquery-ui.min.css" rel="Stylesheet" />
|
||||
<link type="text/css" href="__ROOT_LOCATION__/skin/jquery-ui/jquery-ui.theme.min.css" rel="Stylesheet" />
|
||||
<style>
|
||||
body {
|
||||
background:
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
<script type="text/javascript" src="/skin/jquery-ui/external/jquery/jquery.js"></script>
|
||||
<script type="text/javascript" src="/skin/jquery-ui/jquery-ui.min.js"></script>
|
||||
<link type="text/css" href="__ROOT_LOCATION__/skin/jquery-ui/jquery-ui.min.css" rel="Stylesheet" />
|
||||
<link type="text/css" href="__ROOT_LOCATION__/skin/jquery-ui/jquery-ui.theme.min.css" rel="Stylesheet" />
|
||||
<link type="text/css" href="__ROOT_LOCATION__/skin/taskbar.css" rel="Stylesheet" />
|
||||
<script type="text/javascript" src="__ROOT_LOCATION__/skin/jquery-ui/external/jquery/jquery.js"></script>
|
||||
<script type="text/javascript" src="__ROOT_LOCATION__/skin/jquery-ui/jquery-ui.min.js"></script>
|
||||
<script>
|
||||
var jk = jQuery.noConflict();
|
||||
jk(function() {
|
||||
jk( "#kiwixsearchbox" ).autocomplete({
|
||||
|
||||
source: "/suggest?content=__CONTENT__",
|
||||
source: "__ROOT_LOCATION__/suggest?content=__CONTENT__",
|
||||
dataType: "json",
|
||||
cache: false,
|
||||
|
||||
|
||||
@@ -21,3 +21,4 @@ home.html.tmpl
|
||||
include.html.part
|
||||
taskbar.css
|
||||
taskbar.html.part
|
||||
global_taskbar.html.part
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
<link type="text/css" href="/skin/jquery-ui/jquery-ui.min.css" rel="Stylesheet" />
|
||||
<link type="text/css" href="/skin/jquery-ui/jquery-ui.theme.min.css" rel="Stylesheet" />
|
||||
<span class="kiwix">
|
||||
<span id="kiwixtoolbar" class="ui-widget-header">
|
||||
<div class="kiwix_centered">
|
||||
<div class="kiwix_button_wrapper">
|
||||
<a id="kiwix_serve_taskbar_library_button" href="/"><button>Library</button></a>
|
||||
<a id="kiwix_serve_taskbar_home_button" href="/__CONTENT__/"><button>Home</button></a>
|
||||
<a id="kiwix_serve_taskbar_random_button" href="/random?content=__CONTENT__"><button>Random</button></a>
|
||||
<a id="kiwix_serve_taskbar_library_button" href="__ROOT_LOCATION__/"><button>Library</button></a>
|
||||
<a id="kiwix_serve_taskbar_home_button" href="__ROOT_LOCATION__/__CONTENT__/"><button>Home</button></a>
|
||||
<a id="kiwix_serve_taskbar_random_button" href="__ROOT_LOCATION__/random?content=__CONTENT__"><button>Random</button></a>
|
||||
</div>
|
||||
<div class="kiwix_searchform">
|
||||
<form class="kiwixsearch" method="GET" action="/search" id="kiwixsearchform">
|
||||
<form class="kiwixsearch" method="GET" action="__ROOT_LOCATION__/search" id="kiwixsearchform">
|
||||
<input type="hidden" name="content" value="__CONTENT__" />
|
||||
<input autocomplete="off" class="ui-autocomplete-input" id="kiwixsearchbox" name="pattern" type="text">
|
||||
<input type="submit" value="Search">
|
||||
|
||||
@@ -29,7 +29,7 @@ esac
|
||||
|
||||
sudo apt-get update -qq
|
||||
sudo apt-get install -qq python3-pip ${PACKAGES}
|
||||
pip3 install meson
|
||||
sudo pip3 install meson
|
||||
|
||||
# Ninja
|
||||
cd $HOME
|
||||
|
||||
Reference in New Issue
Block a user