[fix] remove js_dependencies & css_dependencies

Previously plugins could declare js_dependencies and css_dependencies
which in theory would then be embedded in the page by themes.

Practically this does not make sense when you have multiple themes
since the JS & CSS needs to be written with a specific theme in mind
in order to support it.

Which is also why js_dependencies and css_dependencies was actually only
used by the Oscar theme and ignored by the Simple theme because the
Simple theme doesn't bundle jQuery and has a slightly different page
markup.

This commit removes this broken feature and also moves the *.js files in
searx/static/plugins/js/ to searx/static/themes/oscar/src/js/plugins
(where they actually belong).

The oscar-specific CSS is now simply injected via the oscar-specific JS.

Fixes #769.
This commit is contained in:
Martin Fischer 2022-01-20 09:55:53 +01:00
parent 96a1f79c6d
commit 132917ff42
17 changed files with 78 additions and 105 deletions

View file

@ -22,8 +22,6 @@ class Plugin: # pylint: disable=too-few-public-methods
name: str
description: str
default_on: bool
js_dependencies: Tuple[str]
css_dependencies: Tuple[str]
preference_section: str
@ -39,8 +37,6 @@ required_attrs = (
optional_attrs = (
# fmt: off
("js_dependencies", tuple),
("css_dependencies", tuple),
("preference_section", str),
# fmt: on
)
@ -71,9 +67,7 @@ def sync_resource(base_path, resource_path, name, target_dir, plugin_dir):
return join("plugins/external_plugins", plugin_dir, file_name)
def prepare_package_resources(plugin, plugin_module_name):
plugin_base_path = dirname(abspath(plugin.__file__))
def prepare_package_resources(plugin_module_name):
plugin_dir = plugin_module_name
target_dir = join(settings["ui"]["static_path"], "plugins/external_plugins", plugin_dir)
try:
@ -84,20 +78,6 @@ def prepare_package_resources(plugin, plugin_module_name):
resources = []
if hasattr(plugin, "js_dependencies"):
resources.extend(map(basename, plugin.js_dependencies))
plugin.js_dependencies = [
sync_resource(plugin_base_path, x, plugin_module_name, target_dir, plugin_dir)
for x in plugin.js_dependencies
]
if hasattr(plugin, "css_dependencies"):
resources.extend(map(basename, plugin.css_dependencies))
plugin.css_dependencies = [
sync_resource(plugin_base_path, x, plugin_module_name, target_dir, plugin_dir)
for x in plugin.css_dependencies
]
for f in listdir(target_dir):
if basename(f) not in resources:
resource_path = join(target_dir, basename(f))
@ -168,7 +148,7 @@ def load_plugin(plugin_module_name, external):
# copy ressources if this is an external plugin
if external:
prepare_package_resources(plugin, plugin_module_name)
prepare_package_resources(plugin_module_name)
logger.debug("%s: loaded", plugin_module_name)

View file

@ -5,5 +5,4 @@ description = gettext('Automatically load next page when scrolling to bottom of
default_on = False
preference_section = 'ui'
js_dependencies = ('plugins/js/infinite_scroll.js',)
css_dependencies = ('plugins/css/infinite_scroll.css',)
# this plugin is implemented in the themes via JavaScript

View file

@ -23,4 +23,4 @@ description = gettext(
default_on = True
preference_section = 'ui'
js_dependencies = ('plugins/js/search_on_category_select.js',)
# this plugin is implemented in the themes via JavaScript

View file

@ -9,5 +9,4 @@ description = gettext(
default_on = False
preference_section = 'ui'
js_dependencies = ('plugins/js/vim_hotkeys.js',)
css_dependencies = ('plugins/css/vim_hotkeys.css',)
# this plugin is implemented in the themes via JavaScript