Skip to content

SearXNG is a free internet metasearch engine which aggregates results from various search services and databases. Users are neither tracked nor profiled.

[mod] result templates: move iframe to macro and fix page rendering for non-YouTube links (#5960)

Bnyro330d56bba9df
diff --git a/searx/templates/simple/macros.html b/searx/templates/simple/macros.html
index c3e3a9b84..8941b6820 100644
--- a/searx/templates/simple/macros.html
+++ b/searx/templates/simple/macros.html
@@ -67,3 +67,13 @@
class="checkbox-onoff"{{- ' ' -}}
{%- if checked -%} checked{%- endif -%}/>
{%- endmacro -%}
+
+<!-- iframe that additionally sets some extra feature attrs for videos -->
+{%- macro iframe(iframe_src) -%}
+ <iframe data-src="{{iframe_src}}" frameborder="0" allowfullscreen
+ {% if result.parsed_url.hostname in ("www.youtube.com", ) -%}
+ allow="picture-in-picture" referrerpolicy="origin"
+ {%- endif -%}
+ >
+ </iframe>
+{%- endmacro -%}
diff --git a/searx/templates/simple/result_templates/default.html b/searx/templates/simple/result_templates/default.html
index 82d902933..f678c0c52 100644
--- a/searx/templates/simple/result_templates/default.html
+++ b/searx/templates/simple/result_templates/default.html
@@ -1,4 +1,4 @@
-{% from 'simple/macros.html' import result_header, result_sub_header, result_sub_footer, result_footer with context %}
+{% from 'simple/macros.html' import iframe, result_header, result_sub_header, result_sub_footer, result_footer with context %}
{{ result_header(result, favicons, image_proxify) -}}
{{- result_sub_header(result) -}}
@@ -17,7 +17,7 @@
{{- result_sub_footer(result) -}}
{% if result.iframe_src -%}
<div id="result-media-{{ index }}" class="embedded-content invisible">
- <iframe data-src="{{result.iframe_src}}" frameborder="0" allowfullscreen></iframe>
+ {{ iframe(result.iframe_src) }}
</div>
{%- endif %}
{% if result.audio_src -%}
diff --git a/searx/templates/simple/result_templates/videos.html b/searx/templates/simple/result_templates/videos.html
index dcd127679..a336c25ed 100644
--- a/searx/templates/simple/result_templates/videos.html
+++ b/searx/templates/simple/result_templates/videos.html
@@ -1,4 +1,4 @@
-{% from 'simple/macros.html' import result_header, result_sub_header, result_sub_footer, result_footer with context %}
+{% from 'simple/macros.html' import iframe, result_header, result_sub_header, result_sub_footer, result_footer with context %}
{{ result_header(result, favicons, image_proxify) }}
{{ result_sub_header(result) }}
@@ -18,11 +18,7 @@
{{- result_sub_footer(result) -}}
{% if result.iframe_src -%}
<div id="result-video-{{ index }}" class="embedded-video invisible">
- <iframe data-src="{{result.iframe_src}}" frameborder="0" allowfullscreen
- {% if result.parsed_url.hostname in ("www.youtube.com", ) -%}
- allow="picture-in-picture" referrerpolicy="origin">
- {%- endif -%}
- </iframe>
+ {{ iframe(result.iframe_src) }}
</div>
{%- endif %}
{{ result_footer(result) }}