Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
searx-engine
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
searx-engine
Commits
575159b1
Commit
575159b1
authored
Sep 22, 2017
by
jibe-b
Committed by
Noémi Ványi
Nov 01, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[enh] oa_doi_rewrite plugin broadens doai_rewrite
parent
7de8b43e
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
59 additions
and
6 deletions
+59
-6
__init__.py
searx/plugins/__init__.py
+2
-2
oa_doi_rewrite.py
searx/plugins/oa_doi_rewrite.py
+15
-2
preferences.py
searx/preferences.py
+4
-1
settings.yml
searx/settings.yml
+7
-0
preferences.html
searx/templates/oscar/preferences.html
+17
-0
webapp.py
searx/webapp.py
+14
-1
No files found.
searx/plugins/__init__.py
View file @
575159b1
...
...
@@ -22,7 +22,7 @@ if version_info[0] == 3:
logger
=
logger
.
getChild
(
'plugins'
)
from
searx.plugins
import
(
doa
i_rewrite
,
from
searx.plugins
import
(
oa_do
i_rewrite
,
https_rewrite
,
infinite_scroll
,
open_results_on_new_tab
,
...
...
@@ -78,7 +78,7 @@ class PluginStore():
plugins
=
PluginStore
()
plugins
.
register
(
doa
i_rewrite
)
plugins
.
register
(
oa_do
i_rewrite
)
plugins
.
register
(
https_rewrite
)
plugins
.
register
(
infinite_scroll
)
plugins
.
register
(
open_results_on_new_tab
)
...
...
searx/plugins/
doa
i_rewrite.py
→
searx/plugins/
oa_do
i_rewrite.py
View file @
575159b1
from
flask_babel
import
gettext
import
re
from
searx.url_utils
import
urlparse
,
parse_qsl
from
flask
import
request
from
searx
import
settings
regex
=
re
.
compile
(
r'10\.\d{4,9}/[^\s]+'
)
name
=
gettext
(
'
DOA
I rewrite'
)
name
=
gettext
(
'
Open Access DO
I rewrite'
)
description
=
gettext
(
'Avoid paywalls by redirecting to open-access versions of publications when available'
)
default_on
=
False
preference_section
=
'privacy'
doi_resolvers
=
settings
[
'doi_resolvers'
]
def
extract_doi
(
url
):
match
=
regex
.
search
(
url
.
path
)
...
...
@@ -21,12 +26,20 @@ def extract_doi(url):
return
None
def
get_doi_resolver
():
doi_resolvers
=
settings
[
'doi_resolvers'
]
doi_resolver
=
request
.
args
.
get
(
'doi_resolver'
,
request
.
preferences
.
get_value
(
'doi_resolver'
))[
0
]
if
doi_resolver
not
in
doi_resolvers
:
doi_resolvers
=
settings
[
'default_doi_resolver'
]
return
doi_resolvers
[
doi_resolver
]
def
on_result
(
request
,
search
,
result
):
doi
=
extract_doi
(
result
[
'parsed_url'
])
if
doi
and
len
(
doi
)
<
50
:
for
suffix
in
(
'/'
,
'.pdf'
,
'/full'
,
'/meta'
,
'/abstract'
):
if
doi
.
endswith
(
suffix
):
doi
=
doi
[:
-
len
(
suffix
)]
result
[
'url'
]
=
'http://doai.io/'
+
doi
result
[
'url'
]
=
get_doi_resolver
()
+
doi
result
[
'parsed_url'
]
=
urlparse
(
result
[
'url'
])
return
True
searx/preferences.py
View file @
575159b1
...
...
@@ -15,6 +15,7 @@ LANGUAGE_CODES = [l[0] for l in languages]
LANGUAGE_CODES
.
append
(
'all'
)
DISABLED
=
0
ENABLED
=
1
DOI_RESOLVERS
=
[
r
for
r
in
settings
[
'doi_resolvers'
]
.
keys
()]
class
MissingArgumentException
(
Exception
):
...
...
@@ -266,7 +267,9 @@ class Preferences(object):
'results_on_new_tab'
:
MapSetting
(
False
,
map
=
{
'0'
:
False
,
'1'
:
True
,
'False'
:
False
,
'True'
:
True
})}
'True'
:
True
}),
'doi_resolver'
:
MultipleChoiceSetting
([
'oadoi.org'
],
choices
=
DOI_RESOLVERS
),
}
self
.
engines
=
EnginesSetting
(
'engines'
,
choices
=
engines
)
self
.
plugins
=
PluginsSetting
(
'plugins'
,
choices
=
plugins
)
...
...
searx/settings.yml
View file @
575159b1
...
...
@@ -712,3 +712,10 @@ locales:
tr
:
Türkçe (Turkish)
uk
:
українська мова (Ukrainian)
zh
:
中文 (Chinese)
doi_resolvers
:
oadoi.org
:
'
https://oadoi.org/'
doi.org
:
'
https://doi.org/'
doai.io
:
'
http://doai.io/'
default_doi_resolver
:
'
oadoi.org'
searx/templates/oscar/preferences.html
View file @
575159b1
...
...
@@ -223,6 +223,23 @@
</div>
</div>
{% endfor %}
<div
class=
"panel panel-default"
>
<div
class=
"panel-heading"
>
<h3
class=
"panel-title"
>
{{ _('OA DOI rewrite') }}
</h3>
</div>
<div
class=
"panel-body"
>
<div
class=
"col-xs-6 col-sm-4 col-md-6"
>
{{ _('Avoid paywalls by redirecting to open-access versions of publications when available') }}
</div>
<div
class=
"col-xs-6 col-sm-4 col-md-6"
>
<select
class=
"form-control"
id=
'doi_resolver'
name=
'doi_resolver'
>
{% for doi_resolver_name,doi_resolver_url in doi_resolvers.items() %}
<option
value=
"{{ doi_resolver_name }}"
{%
if
doi_resolver_name =
=
current_doi_resolver
%}
selected=
"selected"
{%
endif
%}
>
{{ doi_resolver_name }} - {{ doi_resolver_url }}
</option>
{% endfor %}
</select>
</div>
</div>
</div>
</div>
</fieldset>
</div>
...
...
searx/webapp.py
View file @
575159b1
...
...
@@ -164,6 +164,14 @@ def get_locale():
return
locale
def
get_doi_resolver
():
doi_resolvers
=
settings
[
'doi_resolvers'
]
doi_resolver
=
request
.
args
.
get
(
'doi_resolver'
,
request
.
preferences
.
get_value
(
'doi_resolver'
))[
0
]
if
doi_resolver
not
in
doi_resolvers
:
doi_resolvers
=
settings
[
'default_doi_resolver'
]
return
doi_resolver
# code-highlighter
@
app
.
template_filter
(
'code_highlighter'
)
def
code_highlighter
(
codelines
,
language
=
None
):
...
...
@@ -695,6 +703,8 @@ def preferences():
shortcuts
=
{
y
:
x
for
x
,
y
in
engine_shortcuts
.
items
()},
themes
=
themes
,
plugins
=
plugins
,
doi_resolvers
=
settings
[
'doi_resolvers'
],
current_doi_resolver
=
get_doi_resolver
(),
allowed_plugins
=
allowed_plugins
,
theme
=
get_current_theme_name
(),
preferences_url_params
=
request
.
preferences
.
get_as_url_params
(),
...
...
@@ -839,7 +849,10 @@ def config():
'autocomplete'
:
settings
[
'search'
][
'autocomplete'
],
'safe_search'
:
settings
[
'search'
][
'safe_search'
],
'default_theme'
:
settings
[
'ui'
][
'default_theme'
],
'version'
:
VERSION_STRING
})
'version'
:
VERSION_STRING
,
'doi_resolvers'
:
[
r
for
r
in
search
[
'doi_resolvers'
]],
'default_doi_resolver'
:
settings
[
'default_doi_resolver'
],
})
@
app
.
errorhandler
(
404
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment