Merge pull request #169 from juniorbotelho/feat/wikipedia-language-support

adds language support for Wikipedia results and revert implementation of docker logs using 'docker logs -f librex'
This commit is contained in:
hnhx 2023-02-19 11:54:52 +00:00 committed by GitHub
commit 5dfe95d299
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 35 additions and 9 deletions

View File

@ -8,6 +8,9 @@
"google_language_site" => "",
"google_language_results" => "",
// You can set a language for results in wikipedia
"wikipedia_language" => "en",
// You can use any Invidious instance here
"invidious_instance_for_video_results" => "https://invidious.namazso.eu",

View File

@ -8,6 +8,7 @@
- [Environment variables that can be set in the Docker container](#environment-variables-that-can-be-set-in-the-docker-container)
- [OpenSearch](#opensearch)
- [Search Config](#search-config)
- [Wikipedia](#wikipedia)
- [Applications](#applications)
- [Curl](#curl)
- [Docker version issues](#docker-version-issues)
@ -23,12 +24,14 @@ Dockerized Librex is a way to provide users with yet another way to self-host th
To run librex in a docker container, you can simply use the command:
```sh
docker run -d --name librex \
-e TZ="America/New_York" \
-e CONFIG_GOOGLE_DOMAIN="com" \
-e CONFIG_GOOGLE_LANGUAGE="en" \
-p 8080:8080 \
librex/librex:latest
docker run -d \
--name librex \
-e TZ="America/New_York" \
-e CONFIG_GOOGLE_DOMAIN="com" \
-e CONFIG_GOOGLE_LANGUAGE="en" \
-e CONFIG_WIKIPEDIA_LANGUAGE="en" \
-p 8080:8080 \
librex/librex:latest
```
<br>
@ -51,6 +54,7 @@ services:
- TZ="America/New_York"
- CONFIG_GOOGLE_DOMAIN="com"
- CONFIG_GOOGLE_LANGUAGE="en"
- CONFIG_WIKIPEDIA_LANGUAGE="en"
volumes:
- ./nginx_logs:/var/log/nginx
- ./php_logs:/var/log/php7
@ -90,6 +94,14 @@ This docker image was developed with high configurability in mind, so here is th
<br>
### Wikipedia
| Variables | Default | Examples | Description |
|:----------|:-------------|:---------|:------|
| CONFIG_WIKIPEDIA_LANGUAGE | "en" | "pt", "es", "hu" | Adds language support for Wikipedia results |
<br>
### Applications
| Variables | Default | Examples | Description |

View File

@ -19,13 +19,17 @@ export OPEN_SEARCH_HOST=${OPEN_SEARCH_HOST:-"127.0.0.1"}
# Replace the 'config.php' script, which contains the most common search engine configurations, with these environment setups
# These environment setups can be found in 'config.php', and the default configurations can be useful for most use cases
export CONFIG_GOOGLE_DOMAIN=${CONFIG_GOOGLE_DOMAIN:-".com"}
export CONFIG_GOOGLE_DOMAIN=${CONFIG_GOOGLE_DOMAIN:-"com"}
export CONFIG_GOOGLE_LANGUAGE=${CONFIG_GOOGLE_LANGUAGE:-"en"}
export CONFIG_INVIDIOUS_INSTANCE=${CONFIG_INVIDIOUS_INSTANCE:-"invidious.namazso.eu"}
export CONFIG_HIDDEN_SERVICE_SEARCH=${CONFIG_HIDDEN_SERVICE_SEARCH:-false}
export CONFIG_DISABLE_BITTORRENT_SEARCH=${CONFIG_DISABLE_BITTORRENT_SEARCH:-false}
export CONFIG_BITTORRENT_TRACKERS=${CONFIG_BITTORRENT_TRACKERS:-"&tr=http://nyaa.tracker.wf:7777/announce&tr=udp://open.stealth.si:80/announce&tr=udp://tracker.opentrackr.org:1337/announce&tr=udp://exodus.desync.com:6969/announce&tr=udp://tracker.torrent.eu.org:451/announce"}
# The settings that will be used to handle Wikipedia results displayed on the libreX search page
# the settings below can be edited via environment variables.
export CONFIG_WIKIPEDIA_LANGUAGE=${CONFIG_WIKIPEDIA_LANGUAGE:-${CONFIG_GOOGLE_LANGUAGE}}
# Supported apps integration configuration. These empty spaces can be set up using free hosts as pointers
# A particular example is using the "https://yewtu.be" or a self-hosted host to integrate the invidious app to librex
export APP_INVIDIOUS=${APP_INVIDIOUS:-""}

View File

@ -4,6 +4,8 @@
"google_language" => "${CONFIG_GOOGLE_LANGUAGE}",
"invidious_instance_for_video_results" => "${CONFIG_INVIDIOUS_INSTANCE}",
"wikipedia_language" => "${CONFIG_WIKIPEDIA_LANGUAGE}",
"disable_bittorent_search" => ${CONFIG_DISABLE_BITTORRENT_SEARCH},
"bittorent_trackers" => "${CONFIG_BITTORRENT_TRACKERS}",
"disable_hidden_service_search" => ${CONFIG_HIDDEN_SERVICE_SEARCH},

View File

@ -55,7 +55,8 @@
$url = "https://check.torproject.org/torbulkexitlist";
break;
case 7:
$url = "https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts%7Cpageimages&exintro&explaintext&redirects=1&pithumbsize=500&titles=$query_encoded";
$wikipedia_language = $config->wikipedia_language;
$url = "https://$wikipedia_language.wikipedia.org/w/api.php?format=json&action=query&prop=extracts%7Cpageimages&exintro&explaintext&redirects=1&pithumbsize=500&titles=$query_encoded";
break;
}

View File

@ -1,6 +1,8 @@
<?php
function wikipedia_results($query, $response)
{
global $config;
$query_encoded = urlencode($query);
$json_response = json_decode($response, true);
@ -10,8 +12,10 @@
if (!array_key_exists("missing", $first_page))
{
$description = substr($first_page["extract"], 0, 250) . "...";
$wikipedia_language = $config->wikipedia_language;
$source = check_for_privacy_frontend("https://en.wikipedia.org/wiki/$query");
$source = check_for_privacy_frontend("https://$wikipedia_language.wikipedia.org/wiki/$query");
$response = array(
"special_response" => array(
"response" => htmlspecialchars($description),