Add Commonly Visited sites to SearXNG homepage
This revision is from 2024/07/25 21:38. You can Restore it.
/usr/local/searxng/searxng-src/searx/webapp.py
def get_most_visited_sites(limit=9):
# Placeholder implementation
return [
{"url": "https://example.com", "title": "Example", "favicon": "https://example.com/favicon.ico"},
{"url": "https://wikipedia.org", "title": "Wikipedia", "favicon": "https://wikipedia.org/favicon.ico"},
{"url": "https://github.com", "title": "GitHub", "favicon": "https://github.com/favicon.ico"},
# Add more placeholder sites here
][:limit]
@app.route('/', methods=['GET', 'POST'])
def index():
"""Render index page."""
# redirect to search if there's a query in the request
if request.form.get('q'):
query = ('?' + request.query_string.decode()) if request.query_string else ''
return redirect(url_for('search') + query, 308)
# Get the most visited sites
most_visited_sites = get_most_visited_sites(limit=9)
return render(
'index.html',
selected_categories=get_selected_categories(request.preferences, request.form),
current_locale=request.preferences.get_value("locale"),
most_visited_sites=most_visited_sites
)
/usr/local/searxng/searxng-src/searx/templates/index.html
{% extends "simple/base.html" %}
{% from 'simple/icons.html' import icon_big %}
{% block content %}
<div class="index">
<div class="title"><h1>SearXNG</h1></div>
{% include 'simple/simple_search.html' %}
{% if most_visited_sites %}
<div class="top-sites">
<h2>Top Sites</h2>
<div class="site-grid">
{% for site in most_visited_sites %}
<a href="{{ site.url }}" class="site-tile">
<img src="{{ site.favicon }}" alt="{{ site.title }} favicon">
<span>{{ site.title }}</span>
</a>
{% endfor %}
</div>
</div>
{% endif %}
</div>
{% endblock %}